<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-1.3.433">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

<meta name="author" content="Teresa Sacchet">
<meta name="author" content="Hannah Maruci Aflalo">
<meta name="author" content="Marcus Vinícius Chevitarese Alves">
<meta name="author" content="Vanilda Souza Chaves">

<title>Paper RBCP 2025</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
  width: 0.8em;
  margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ 
  vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
  }
pre.numberSource { margin-left: 3em;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>


<script src="artigo-rbcp-2025_EN_files/libs/clipboard/clipboard.min.js"></script>
<script src="artigo-rbcp-2025_EN_files/libs/quarto-html/quarto.js"></script>
<script src="artigo-rbcp-2025_EN_files/libs/quarto-html/popper.min.js"></script>
<script src="artigo-rbcp-2025_EN_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="artigo-rbcp-2025_EN_files/libs/quarto-html/anchor.min.js"></script>
<link href="artigo-rbcp-2025_EN_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="artigo-rbcp-2025_EN_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="artigo-rbcp-2025_EN_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="artigo-rbcp-2025_EN_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="artigo-rbcp-2025_EN_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">

<link href="artigo-rbcp-2025_EN_files/libs/tabwid-1.1.3/tabwid.css" rel="stylesheet">
<script src="artigo-rbcp-2025_EN_files/libs/tabwid-1.1.3/tabwid.js"></script>
<link href="artigo-rbcp-2025_EN_files/libs/pagedtable-1.1/css/pagedtable.css" rel="stylesheet">
<script src="artigo-rbcp-2025_EN_files/libs/pagedtable-1.1/js/pagedtable.js"></script>


</head>

<body>

<header id="title-block-header" class="quarto-title-block default page-columns page-full">
  <div class="quarto-title-banner page-columns page-full">
    <div class="quarto-title column-body">
      <div class="quarto-title-block"><div><h1 class="title">Paper RBCP 2025</h1><button type="button" class="btn code-tools-button dropdown-toggle" id="quarto-code-tools-menu" data-bs-toggle="dropdown" aria-expanded="false"><i class="bi"></i> Code</button><ul class="dropdown-menu dropdown-menu-end" aria-labelelledby="quarto-code-tools-menu"><li><a id="quarto-show-all-code" class="dropdown-item" href="javascript:void(0)" role="button">Show All Code</a></li><li><a id="quarto-hide-all-code" class="dropdown-item" href="javascript:void(0)" role="button">Hide All Code</a></li><li><hr class="dropdown-divider"></li><li><a id="quarto-view-source" class="dropdown-item" href="javascript:void(0)" role="button">View Source</a></li></ul></div></div>
                      </div>
  </div>
    
  <div class="quarto-title-meta-author">
    <div class="quarto-title-meta-heading">Authors</div>
    <div class="quarto-title-meta-heading">Affiliations</div>
    
      <div class="quarto-title-meta-contents">
      <p class="author">Teresa Sacchet <a href="https://orcid.org/0000-0002-1592-2169" class="quarto-title-author-orcid"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=="></a></p>
    </div>
      <div class="quarto-title-meta-contents">
          <p class="affiliation">
              Federal University of Rio Grande do Sul (UFRGS)
            </p>
        </div>
        <div class="quarto-title-meta-contents">
      <p class="author">Hannah Maruci Aflalo <a href="https://orcid.org/0000-0002-4820-2942" class="quarto-title-author-orcid"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=="></a></p>
    </div>
      <div class="quarto-title-meta-contents">
          <p class="affiliation">
              Brazilian Centre for Analysis and Planning (CEBRAP)
            </p>
        </div>
        <div class="quarto-title-meta-contents">
      <p class="author">Marcus Vinícius Chevitarese Alves <a href="https://orcid.org/0009-0002-6265-1004" class="quarto-title-author-orcid"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=="></a></p>
    </div>
      <div class="quarto-title-meta-contents">
          <p class="affiliation">
              Center for Training and Improvement - Chamber of Deputies (CEFOR)
            </p>
          <p class="affiliation">
              National Observatory of Women in Politics - Chamber of Deputies (ONMP)
            </p>
        </div>
        <div class="quarto-title-meta-contents">
      <p class="author">Vanilda Souza Chaves <a href="https://orcid.org/0000-0002-0349-3862" class="quarto-title-author-orcid"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=="></a></p>
    </div>
      <div class="quarto-title-meta-contents">
          <p class="affiliation">
              University of São Paulo (USP)
            </p>
        </div>
      </div>

  <div class="quarto-title-meta">

        
    
      
    </div>
    
  
  </header><div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
  <nav id="TOC" role="doc-toc" class="toc-active">
    <h2 id="toc-title">Table of contents</h2>
   
  <ul>
  <li><a href="#presentation" id="toc-presentation" class="nav-link active" data-scroll-target="#presentation">Presentation</a></li>
  <li><a href="#objective-and-hypotheses" id="toc-objective-and-hypotheses" class="nav-link" data-scroll-target="#objective-and-hypotheses">Objective and hypotheses</a></li>
  <li><a href="#environment-setup" id="toc-environment-setup" class="nav-link" data-scroll-target="#environment-setup">Environment setup</a>
  <ul class="collapse">
  <li><a href="#clear-all-objects" id="toc-clear-all-objects" class="nav-link" data-scroll-target="#clear-all-objects">Clear all objects</a></li>
  <li><a href="#load-required-packages" id="toc-load-required-packages" class="nav-link" data-scroll-target="#load-required-packages">Load required packages</a></li>
  </ul></li>
  <li><a href="#data-preparation" id="toc-data-preparation" class="nav-link" data-scroll-target="#data-preparation">Data preparation</a>
  <ul class="collapse">
  <li><a href="#campaign-revenue-data-preparation" id="toc-campaign-revenue-data-preparation" class="nav-link" data-scroll-target="#campaign-revenue-data-preparation">Campaign revenue data preparation</a>
  <ul class="collapse">
  <li><a href="#campaign-revenue-data-by-source-loading" id="toc-campaign-revenue-data-by-source-loading" class="nav-link" data-scroll-target="#campaign-revenue-data-by-source-loading">Campaign revenue data by source loading</a></li>
  <li><a href="#create-the-codebook-for-receitas_fonte-database" id="toc-create-the-codebook-for-receitas_fonte-database" class="nav-link" data-scroll-target="#create-the-codebook-for-receitas_fonte-database">Create the codebook for <em>receitas_fonte</em> database</a></li>
  <li><a href="#standardizing-campaign-revenue-data-by-source" id="toc-standardizing-campaign-revenue-data-by-source" class="nav-link" data-scroll-target="#standardizing-campaign-revenue-data-by-source">Standardizing campaign revenue data by source</a></li>
  <li><a href="#loading-campaign-resource-data-by-time" id="toc-loading-campaign-resource-data-by-time" class="nav-link" data-scroll-target="#loading-campaign-resource-data-by-time">Loading campaign resource data by time</a></li>
  <li><a href="#create-the-codebook-for-receitas_por_tempo_sem_form-database" id="toc-create-the-codebook-for-receitas_por_tempo_sem_form-database" class="nav-link" data-scroll-target="#create-the-codebook-for-receitas_por_tempo_sem_form-database">Create the codebook for <em>receitas_por_tempo_sem_form</em> database</a></li>
  </ul></li>
  <li><a href="#candidacy-data" id="toc-candidacy-data" class="nav-link" data-scroll-target="#candidacy-data">Candidacy data</a>
  <ul class="collapse">
  <li><a href="#loading-candidacy-data" id="toc-loading-candidacy-data" class="nav-link" data-scroll-target="#loading-candidacy-data">Loading candidacy data</a></li>
  </ul></li>
  <li><a href="#data-preparation-1" id="toc-data-preparation-1" class="nav-link" data-scroll-target="#data-preparation-1">Data preparation</a>
  <ul class="collapse">
  <li><a href="#standardizing-variable-names" id="toc-standardizing-variable-names" class="nav-link" data-scroll-target="#standardizing-variable-names">Standardizing variable names</a></li>
  <li><a href="#standardizing-campaign-revenue-data-by-time" id="toc-standardizing-campaign-revenue-data-by-time" class="nav-link" data-scroll-target="#standardizing-campaign-revenue-data-by-time">Standardizing campaign revenue data by time</a></li>
  <li><a href="#standardizing-candidacies-data" id="toc-standardizing-candidacies-data" class="nav-link" data-scroll-target="#standardizing-candidacies-data">Standardizing candidacies data</a></li>
  <li><a href="#data-aggregation" id="toc-data-aggregation" class="nav-link" data-scroll-target="#data-aggregation">Data aggregation</a></li>
  </ul></li>
  </ul></li>
  <li><a href="#data-analysis" id="toc-data-analysis" class="nav-link" data-scroll-target="#data-analysis">Data Analysis</a>
  <ul class="collapse">
  <li><a href="#preliminary-analysis---total-resources-transfers-between-candidate-providers-by-resource-type" id="toc-preliminary-analysis---total-resources-transfers-between-candidate-providers-by-resource-type" class="nav-link" data-scroll-target="#preliminary-analysis---total-resources-transfers-between-candidate-providers-by-resource-type">Preliminary Analysis - total resources transfers between candidate providers, by resource type</a></li>
  <li><a href="#distribution-of-cash-equivalent-and-cash-funding" id="toc-distribution-of-cash-equivalent-and-cash-funding" class="nav-link" data-scroll-target="#distribution-of-cash-equivalent-and-cash-funding"><strong>Distribution of Cash-Equivalent and Cash Funding</strong></a>
  <ul class="collapse">
  <li><a href="#graph-1---proportion-of-cash-equivalent-funds-of-candidates-for-federal-deputy-by-race-and-gender" id="toc-graph-1---proportion-of-cash-equivalent-funds-of-candidates-for-federal-deputy-by-race-and-gender" class="nav-link" data-scroll-target="#graph-1---proportion-of-cash-equivalent-funds-of-candidates-for-federal-deputy-by-race-and-gender">Graph 1 - Proportion of cash-equivalent funds of candidates for federal deputy, by race and gender</a></li>
  <li><a href="#graph-2---proportion-of-cash-equivalent-funds-of-candidates-for-state-deputy-by-race-and-gender" id="toc-graph-2---proportion-of-cash-equivalent-funds-of-candidates-for-state-deputy-by-race-and-gender" class="nav-link" data-scroll-target="#graph-2---proportion-of-cash-equivalent-funds-of-candidates-for-state-deputy-by-race-and-gender">Graph 2 - Proportion of cash-equivalent funds of candidates for state deputy, by race and gender</a></li>
  </ul></li>
  <li><a href="#when-the-funds-were-transferred" id="toc-when-the-funds-were-transferred" class="nav-link" data-scroll-target="#when-the-funds-were-transferred">When the funds were transferred</a>
  <ul class="collapse">
  <li><a href="#graph-3---ratio-between-the-group-and-the-overall-average-of-public-funding-of-candidates-for-federal-deputy-by-gender-and-race-each-week" id="toc-graph-3---ratio-between-the-group-and-the-overall-average-of-public-funding-of-candidates-for-federal-deputy-by-gender-and-race-each-week" class="nav-link" data-scroll-target="#graph-3---ratio-between-the-group-and-the-overall-average-of-public-funding-of-candidates-for-federal-deputy-by-gender-and-race-each-week">Graph 3 - Ratio between the group and the overall average of public funding of candidates for federal deputy by gender and race, each week</a></li>
  <li><a href="#graph-4---ratio-between-the-group-and-the-overall-average-of-public-funding-of-candidates-for-state-deputy-by-gender-and-colorrace-each-week" id="toc-graph-4---ratio-between-the-group-and-the-overall-average-of-public-funding-of-candidates-for-state-deputy-by-gender-and-colorrace-each-week" class="nav-link" data-scroll-target="#graph-4---ratio-between-the-group-and-the-overall-average-of-public-funding-of-candidates-for-state-deputy-by-gender-and-colorrace-each-week">Graph 4 - Ratio between the group and the overall average of public funding of candidates for state deputy by gender and color/race, each week</a></li>
  </ul></li>
  <li><a href="#transfers-between-candidate-providers" id="toc-transfers-between-candidate-providers" class="nav-link" data-scroll-target="#transfers-between-candidate-providers">Transfers between candidate providers</a>
  <ul class="collapse">
  <li><a href="#table-1---transfer-of-funds-between-candidates-by-gender" id="toc-table-1---transfer-of-funds-between-candidates-by-gender" class="nav-link" data-scroll-target="#table-1---transfer-of-funds-between-candidates-by-gender">Table 1 - Transfer of funds between candidates, by gender</a></li>
  <li><a href="#table-2---transfer-of-funds-between-candidates-by-race" id="toc-table-2---transfer-of-funds-between-candidates-by-race" class="nav-link" data-scroll-target="#table-2---transfer-of-funds-between-candidates-by-race">Table 2 - Transfer of funds between candidates, by race</a></li>
  </ul></li>
  <li><a href="#transfers-and-reelection" id="toc-transfers-and-reelection" class="nav-link" data-scroll-target="#transfers-and-reelection">Transfers and Reelection</a>
  <ul class="collapse">
  <li><a href="#create-dataset-for-tables-3-and-4" id="toc-create-dataset-for-tables-3-and-4" class="nav-link" data-scroll-target="#create-dataset-for-tables-3-and-4">Create dataset for Tables 3 and 4</a></li>
  <li><a href="#table-3---proportion-and-average-funds-of-candidates-for-federal-deputy-by-gender-race-and-dispute-status-challenger-x-incumbent" id="toc-table-3---proportion-and-average-funds-of-candidates-for-federal-deputy-by-gender-race-and-dispute-status-challenger-x-incumbent" class="nav-link" data-scroll-target="#table-3---proportion-and-average-funds-of-candidates-for-federal-deputy-by-gender-race-and-dispute-status-challenger-x-incumbent">Table 3 - Proportion and average funds of candidates for federal deputy by gender, race and dispute status (challenger x incumbent)</a></li>
  <li><a href="#table-4---proportion-and-average-funds-of-candidates-for-state-deputy-by-gender-race-and-dispute-status-challenger-x-incumbent" id="toc-table-4---proportion-and-average-funds-of-candidates-for-state-deputy-by-gender-race-and-dispute-status-challenger-x-incumbent" class="nav-link" data-scroll-target="#table-4---proportion-and-average-funds-of-candidates-for-state-deputy-by-gender-race-and-dispute-status-challenger-x-incumbent">Table 4 - Proportion and average funds of candidates for state deputy by gender, race and dispute status (challenger x incumbent)</a></li>
  </ul></li>
  <li><a href="#appendix-a---table-1---public-resource-transfers-between-candidate-providers-by-gender-and-race" id="toc-appendix-a---table-1---public-resource-transfers-between-candidate-providers-by-gender-and-race" class="nav-link" data-scroll-target="#appendix-a---table-1---public-resource-transfers-between-candidate-providers-by-gender-and-race">Appendix A - Table 1 - Public resource transfers between candidate providers, by gender and race</a></li>
  <li><a href="#appendix-b" id="toc-appendix-b" class="nav-link" data-scroll-target="#appendix-b">Appendix B</a>
  <ul class="collapse">
  <li><a href="#table-b-1---average-public-resource-of-federal-deputies-by-week-of-spending-gender-and-race" id="toc-table-b-1---average-public-resource-of-federal-deputies-by-week-of-spending-gender-and-race" class="nav-link" data-scroll-target="#table-b-1---average-public-resource-of-federal-deputies-by-week-of-spending-gender-and-race">Table B-1 - Average public resource of federal deputies by week of spending, gender and race</a></li>
  <li><a href="#section" id="toc-section" class="nav-link" data-scroll-target="#section"></a></li>
  <li><a href="#table-b-2---average-public-resource-of-state-deputy-by-revenue-registration-week-gender-and-race" id="toc-table-b-2---average-public-resource-of-state-deputy-by-revenue-registration-week-gender-and-race" class="nav-link" data-scroll-target="#table-b-2---average-public-resource-of-state-deputy-by-revenue-registration-week-gender-and-race">Table B-2 - Average public resource of state deputy by revenue registration week, gender and race</a></li>
  <li><a href="#section-1" id="toc-section-1" class="nav-link" data-scroll-target="#section-1"></a></li>
  </ul></li>
  </ul></li>
  </ul>
</nav>
</div>
<main class="content quarto-banner-title-block" id="quarto-document-content">




<div class="cell">
<style type="text/css">
.output {
max-width: 1000px;
max-height: 500px;
overflow-x: scroll;
overflow-y: scroll;
}
</style>
</div>
<hr>
<section id="presentation" class="level1">
<h1>Presentation</h1>
<p>We produced this document, in Quarto notebook format as a subsidy for the analysis of data from the article to be published in the Brazilian Journal of Political Science (RBCP).</p>
<p>The original data were obtained from the <a href="https://dadosabertos.tse.jus.br/" title="TSE Open Data Portal">TSE Open Data Portal</a> and were subsequently subjected to a cleaning and unification process. This process is not entirely covered by this document, which focuses on the analysis of the data itself. However, details about the process can be obtained through the authors’ emails.</p>
</section>
<section id="objective-and-hypotheses" class="level1">
<h1>Objective and hypotheses</h1>
<p>This study aims to conduct an exploratory analysis of the accountability data of candidates for proportional positions (federal deputy and state deputy) in the 2022 elections, comparing them to the data from the 2018 elections and making a gender and color/race cut, with a view to verifying whether there were differences in the distribution of revenues by these groups, in the context of the new electoral legal norms that took effect in the last elections.</p>
</section>
<section id="environment-setup" class="level1">
<h1>Environment setup</h1>
<section id="clear-all-objects" class="level2">
<h2 class="anchored" data-anchor-id="clear-all-objects">Clear all objects</h2>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(<span class="at">list=</span><span class="fu">ls</span>())</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="load-required-packages" class="level2">
<h2 class="anchored" data-anchor-id="load-required-packages">Load required packages</h2>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidyr)</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(dplyr)</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(stringr)</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(knitr)</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(DescTools)</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(summarytools)</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(afex)</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggpubr)</span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(broom)</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(openxlsx)</span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(lubridate)</span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(scales)</span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(patchwork)</span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(Cairo)</span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(viridis)</span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(flextable)</span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(officer)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} length(.packages())</code> libraries loaded.</p>
</section>
</section>
<section id="data-preparation" class="level1">
<h1>Data preparation</h1>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>We used three initial datasets in this work: two with campaign revenue data and one with candidate data.</p>
<p>The first campaign revenue dataset was aggregated by funding source; the second was aggregated by period (week).</p>
<p>We also generated three codebooks, one for each initial dataset. The remaining datasets used in this notebook were based on these.</p>
</div>
</div>
<section id="campaign-revenue-data-preparation" class="level2">
<h2 class="anchored" data-anchor-id="campaign-revenue-data-preparation">Campaign revenue data preparation</h2>
<section id="campaign-revenue-data-by-source-loading" class="level3">
<h3 class="anchored" data-anchor-id="campaign-revenue-data-by-source-loading">Campaign revenue data by source loading</h3>
<p>Upload candidate income data by income source and funding source</p>
<p>Data generation date: 2023-09-26</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>nome_base_receitas_fonte <span class="ot">&lt;-</span> <span class="st">"../Dados/candidatos_2018_2022_receitas_por_fonte_2023_09_26.dsv"</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Receitas sem formatação prévia</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>receitas_fonte <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>  nome_base_receitas_fonte,</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>  <span class="at">header =</span> <span class="cn">TRUE</span>,</span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">sep =</span> <span class="st">";"</span>,                     </span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>  <span class="at">fileEncoding =</span> <span class="st">"utf-8"</span>,</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a>  <span class="at">dec =</span> <span class="st">","</span>,</span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a>  <span class="at">stringsAsFactors =</span> <span class="cn">FALSE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas_fonte)</code> lines loaded.</p>
</section>
<section id="create-the-codebook-for-receitas_fonte-database" class="level3">
<h3 class="anchored" data-anchor-id="create-the-codebook-for-receitas_fonte-database">Create the codebook for <em>receitas_fonte</em> database</h3>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>descriptions <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">'Election year'</span>,</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Position description'</span>,</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'State acronym'</span>,</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Party acronyn'</span>,</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Candidate name'</span>,</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Candidate ID'</span>,</span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Candidate sequential'</span>,</span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Candidate gender description'</span>,</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Race description'</span>,</span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Revenue source description'</span>,</span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Resource source description'</span>,</span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Revenue kind description'</span>,</span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Donor ID'</span>,</span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Campaign accountant ID'</span>,</span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Donor candidate sequential'</span>,</span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Donor candidate gender'</span>,</span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Donor candidate race'</span>,</span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Total revenue'</span>,</span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Vote tally status'</span>,</span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Reelection status'</span>)</span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true" tabindex="-1"></a>code_book_1 <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">variable_name =</span> <span class="fu">names</span>(receitas_fonte),</span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true" tabindex="-1"></a>                          <span class="at">variable_class =</span> <span class="fu">sapply</span>(receitas_fonte, class),</span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true" tabindex="-1"></a>                          <span class="at">variable_desc =</span> descriptions)</span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true" tabindex="-1"></a>code_book_1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["variable_name"],"name":[1],"type":["chr"],"align":["left"]},{"label":["variable_class"],"name":[2],"type":["chr"],"align":["left"]},{"label":["variable_desc"],"name":[3],"type":["chr"],"align":["left"]}],"data":[{"1":"ANO_ELEICAO","2":"integer","3":"Election year","_rn_":"ANO_ELEICAO"},{"1":"DS_CARGO","2":"character","3":"Position description","_rn_":"DS_CARGO"},{"1":"SG_UF","2":"character","3":"State acronym","_rn_":"SG_UF"},{"1":"SG_PARTIDO","2":"character","3":"Party acronyn","_rn_":"SG_PARTIDO"},{"1":"NM_CANDIDATO","2":"character","3":"Candidate name","_rn_":"NM_CANDIDATO"},{"1":"NR_CPF_CANDIDATO","2":"numeric","3":"Candidate ID","_rn_":"NR_CPF_CANDIDATO"},{"1":"SQ_CANDIDATO","2":"numeric","3":"Candidate sequential","_rn_":"SQ_CANDIDATO"},{"1":"DS_GENERO","2":"character","3":"Candidate gender description","_rn_":"DS_GENERO"},{"1":"DS_COR_RACA","2":"character","3":"Race description","_rn_":"DS_COR_RACA"},{"1":"DS_FONTE_RECEITA","2":"character","3":"Revenue source description","_rn_":"DS_FONTE_RECEITA"},{"1":"DS_FONTE_RECURSO","2":"character","3":"Resource source description","_rn_":"DS_FONTE_RECURSO"},{"1":"DS_ESPECIE_RECEITA","2":"character","3":"Revenue kind description","_rn_":"DS_ESPECIE_RECEITA"},{"1":"NR_CPF_CNPJ_DOADOR","2":"numeric","3":"Donor ID","_rn_":"NR_CPF_CNPJ_DOADOR"},{"1":"NR_CNPJ_PRESTADOR_CONTA","2":"numeric","3":"Campaign accountant ID","_rn_":"NR_CNPJ_PRESTADOR_CONTA"},{"1":"SQ_CANDIDATO_DOADOR","2":"numeric","3":"Donor candidate sequential","_rn_":"SQ_CANDIDATO_DOADOR"},{"1":"DS_GENERO_DOADOR","2":"character","3":"Donor candidate gender","_rn_":"DS_GENERO_DOADOR"},{"1":"DS_COR_RACA_DOADOR","2":"character","3":"Donor candidate race","_rn_":"DS_COR_RACA_DOADOR"},{"1":"TOTAL_RECEITA","2":"numeric","3":"Total revenue","_rn_":"TOTAL_RECEITA"},{"1":"DS_SIT_TOT_TURNO","2":"character","3":"Vote tally status","_rn_":"DS_SIT_TOT_TURNO"},{"1":"ST_REELEICAO","2":"character","3":"Reelection status","_rn_":"ST_REELEICAO"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
<p>Save codebook 1</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(code_book_1, </span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>           <span class="st">'..//Dados//Code_Book_1.xlsx'</span>,</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>           <span class="at">sheetName =</span> <span class="st">"codebook1"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="standardizing-campaign-revenue-data-by-source" class="level3">
<h3 class="anchored" data-anchor-id="standardizing-campaign-revenue-data-by-source">Standardizing campaign revenue data by source</h3>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="co"># prepara dados de receitas para a análise</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>receitas <span class="ot">&lt;-</span> receitas_fonte <span class="sc">%&gt;%</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>    <span class="at">ano_eleicao =</span> <span class="fu">as.factor</span>(ANO_ELEICAO),</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">NR_CPF_CANDIDATO =</span> <span class="fu">as.character</span>(NR_CPF_CANDIDATO),</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">uf =</span> <span class="fu">as.factor</span>(SG_UF),</span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">genero =</span> <span class="fu">case_when</span>(</span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO) <span class="sc">==</span> <span class="st">'FEMININO'</span> <span class="sc">~</span> <span class="st">'Women'</span>,</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO) <span class="sc">==</span> <span class="st">'MASCULINO'</span> <span class="sc">~</span> <span class="st">'Men'</span>,</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Others'</span></span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">genero_doador =</span> <span class="fu">case_when</span>(</span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO_DOADOR) <span class="sc">==</span> <span class="st">'FEMININO'</span> <span class="sc">~</span> <span class="st">'Women'</span>,</span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO_DOADOR) <span class="sc">==</span> <span class="st">'MASCULINO'</span> <span class="sc">~</span> <span class="st">'Men'</span>,</span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Others'</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">cor_raca =</span> <span class="fu">case_when</span>(</span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA <span class="sc">==</span> <span class="st">'PARDA'</span> <span class="sc">|</span> DS_COR_RACA <span class="sc">==</span> <span class="st">'PRETA'</span> <span class="sc">~</span> <span class="st">'Black'</span>,</span>
<span id="cb6-19"><a href="#cb6-19" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA <span class="sc">==</span> <span class="st">'BRANCA'</span> <span class="sc">~</span> <span class="st">'White'</span>,</span>
<span id="cb6-20"><a href="#cb6-20" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Other races'</span></span>
<span id="cb6-21"><a href="#cb6-21" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb6-22"><a href="#cb6-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">cor_raca_doador =</span> <span class="fu">case_when</span>(</span>
<span id="cb6-23"><a href="#cb6-23" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA_DOADOR <span class="sc">==</span> <span class="st">'PARDA'</span> <span class="sc">|</span> DS_COR_RACA_DOADOR <span class="sc">==</span> <span class="st">'PRETA'</span> <span class="sc">~</span> <span class="st">'Black'</span>,</span>
<span id="cb6-24"><a href="#cb6-24" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA_DOADOR <span class="sc">==</span> <span class="st">'BRANCA'</span> <span class="sc">~</span> <span class="st">'White'</span>,</span>
<span id="cb6-25"><a href="#cb6-25" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Other races'</span></span>
<span id="cb6-26"><a href="#cb6-26" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb6-27"><a href="#cb6-27" aria-hidden="true" tabindex="-1"></a>    <span class="at">eleito =</span> <span class="fu">case_when</span>(</span>
<span id="cb6-28"><a href="#cb6-28" aria-hidden="true" tabindex="-1"></a>      DS_SIT_TOT_TURNO <span class="sc">%like%</span> <span class="st">'ELEITO%'</span> <span class="sc">~</span> <span class="st">'Elected'</span>,</span>
<span id="cb6-29"><a href="#cb6-29" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Not elected'</span></span>
<span id="cb6-30"><a href="#cb6-30" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb6-31"><a href="#cb6-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">fonte_receita =</span> <span class="fu">str_to_upper</span>(DS_FONTE_RECEITA),</span>
<span id="cb6-32"><a href="#cb6-32" aria-hidden="true" tabindex="-1"></a>    <span class="at">tipo_fonte_receita =</span> <span class="fu">case_when</span>(</span>
<span id="cb6-33"><a href="#cb6-33" aria-hidden="true" tabindex="-1"></a>      fonte_receita <span class="sc">==</span> <span class="st">'FUNDO ESPECIAL'</span> <span class="sc">~</span> <span class="st">'FEFC'</span>,</span>
<span id="cb6-34"><a href="#cb6-34" aria-hidden="true" tabindex="-1"></a>      fonte_receita <span class="sc">==</span> <span class="st">'FUNDO PARTIDARIO'</span> <span class="sc">~</span> <span class="st">'FP'</span>,</span>
<span id="cb6-35"><a href="#cb6-35" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Outros recursos'</span></span>
<span id="cb6-36"><a href="#cb6-36" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb6-37"><a href="#cb6-37" aria-hidden="true" tabindex="-1"></a>    <span class="at">tipo_recurso =</span> <span class="fu">case_when</span>(</span>
<span id="cb6-38"><a href="#cb6-38" aria-hidden="true" tabindex="-1"></a>      tipo_fonte_receita <span class="sc">==</span> <span class="st">'Outros recursos'</span> <span class="sc">~</span> <span class="st">'Private'</span>,</span>
<span id="cb6-39"><a href="#cb6-39" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Public'</span></span>
<span id="cb6-40"><a href="#cb6-40" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb6-41"><a href="#cb6-41" aria-hidden="true" tabindex="-1"></a>    <span class="at">especie_recurso =</span> <span class="fu">case_when</span>(</span>
<span id="cb6-42"><a href="#cb6-42" aria-hidden="true" tabindex="-1"></a>      DS_ESPECIE_RECEITA <span class="sc">==</span> <span class="st">'Estimado'</span> <span class="sc">~</span> <span class="st">'Cash-equivalent'</span>,</span>
<span id="cb6-43"><a href="#cb6-43" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Cash'</span></span>
<span id="cb6-44"><a href="#cb6-44" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb6-45"><a href="#cb6-45" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb6-46"><a href="#cb6-46" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-47"><a href="#cb6-47" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(receitas_fonte)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas)</code> lines standardized.</p>
</section>
<section id="loading-campaign-resource-data-by-time" class="level3">
<h3 class="anchored" data-anchor-id="loading-campaign-resource-data-by-time">Loading campaign resource data by time</h3>
<p>Uploads a database of income from eligible candidates with detailed declared income by time, in 2018 and 2022</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>nome_base_receitas <span class="ot">&lt;-</span> <span class="st">"../Dados/receitas_por_data_e_origem_2018_2022_v_2023_09_27.dsv"</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Database with raw data</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>receitas_por_tempo_sem_form <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a>  nome_base_receitas,</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a>  <span class="at">header =</span> <span class="cn">TRUE</span>,</span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">sep =</span> <span class="st">";"</span>,                     </span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a>  <span class="at">fileEncoding =</span> <span class="st">"utf-8"</span>,</span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a>  <span class="at">dec =</span> <span class="st">","</span>,</span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a>  <span class="at">stringsAsFactors =</span> <span class="cn">FALSE</span>,</span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a>  <span class="at">colClasses=</span><span class="fu">c</span>(<span class="st">"NR_CPF_CANDIDATO"</span><span class="ot">=</span><span class="st">"character"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas_por_tempo_sem_form)</code> lines loaded.</p>
</section>
<section id="create-the-codebook-for-receitas_por_tempo_sem_form-database" class="level3">
<h3 class="anchored" data-anchor-id="create-the-codebook-for-receitas_por_tempo_sem_form-database">Create the codebook for <em>receitas_por_tempo_sem_form</em> database</h3>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>descriptions_2 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">'Election year'</span>,</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Position description'</span>,</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'State acronym'</span>,</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Revenue source description'</span>,</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Resource source description'</span>,</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Revenue kind description'</span>,</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Revenue date'</span>,</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Candidate sequential'</span>,</span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Candidate ID'</span>,</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Total revenue'</span>)</span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a>code_book_2 <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(</span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_name =</span> <span class="fu">names</span>(receitas_por_tempo_sem_form),</span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_class =</span> <span class="fu">sapply</span>(receitas_por_tempo_sem_form, class),</span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_desc =</span> descriptions_2)</span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true" tabindex="-1"></a>code_book_2 <span class="sc">%&gt;%</span> </span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(variable_name, </span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true" tabindex="-1"></a>         variable_class, </span>
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true" tabindex="-1"></a>         variable_desc)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["variable_name"],"name":[1],"type":["chr"],"align":["left"]},{"label":["variable_class"],"name":[2],"type":["chr"],"align":["left"]},{"label":["variable_desc"],"name":[3],"type":["chr"],"align":["left"]}],"data":[{"1":"ANO_ELEICAO","2":"integer","3":"Election year","_rn_":"ANO_ELEICAO"},{"1":"DS_CARGO","2":"character","3":"Position description","_rn_":"DS_CARGO"},{"1":"SG_UF","2":"character","3":"State acronym","_rn_":"SG_UF"},{"1":"DS_FONTE_RECEITA","2":"character","3":"Revenue source description","_rn_":"DS_FONTE_RECEITA"},{"1":"DS_FONTE_RECURSO","2":"character","3":"Resource source description","_rn_":"DS_FONTE_RECURSO"},{"1":"DS_ESPECIE_RECEITA","2":"character","3":"Revenue kind description","_rn_":"DS_ESPECIE_RECEITA"},{"1":"DT_RECEITA","2":"character","3":"Revenue date","_rn_":"DT_RECEITA"},{"1":"SQ_CANDIDATO","2":"numeric","3":"Candidate sequential","_rn_":"SQ_CANDIDATO"},{"1":"NR_CPF_CANDIDATO","2":"character","3":"Candidate ID","_rn_":"NR_CPF_CANDIDATO"},{"1":"TOTAL_RECEITA","2":"numeric","3":"Total revenue","_rn_":"TOTAL_RECEITA"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
<p>Save codebook 2</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(code_book_2, </span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>           <span class="st">'..//Dados//Code_Book_2.xlsx'</span>,</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>           <span class="at">sheetName =</span> <span class="st">"codebook2"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
</section>
<section id="candidacy-data" class="level2">
<h2 class="anchored" data-anchor-id="candidacy-data">Candidacy data</h2>
<p>It loads the database of candidates in 2018 and 2022 and shows the overall total of candidates – in this case, no filter was applied, therefore, candidates classified as “irregular” by the TSE were also considered.</p>
<section id="loading-candidacy-data" class="level3">
<h3 class="anchored" data-anchor-id="loading-candidacy-data">Loading candidacy data</h3>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>nome_base_candidatos <span class="ot">&lt;-</span> <span class="st">"../Dados/candidatos_2018_2022_v_2023_09_27.dsv"</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a>candidatos_sem_form <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a>  nome_base_candidatos,</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a>  <span class="at">header =</span> <span class="cn">TRUE</span>,</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a>  <span class="at">sep =</span> <span class="st">";"</span>,                     </span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">fileEncoding =</span> <span class="st">"utf-8"</span>,</span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a>  <span class="at">stringsAsFactors =</span> <span class="cn">FALSE</span>,</span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a>  <span class="at">colClasses=</span><span class="fu">c</span>(<span class="st">"NR_CPF_CANDIDATO"</span><span class="ot">=</span><span class="st">"character"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(candidatos_sem_form)</code> lines loaded.</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>descriptions_3 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"Election year"</span>,</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"State name"</span>,</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"State acronym"</span>,</span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Position description"</span>,</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Party acronyn"</span>,</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidate name"</span>,</span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidate's ballot box name"</span>,</span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidate sequential ID"</span>,</span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidate ID"</span>,</span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidacy status description"</span>,</span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidacy detailed status description"</span>,</span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Vote tally status"</span>,</span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Nationality of the candidate"</span>,</span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Acronym of place (state) of birth"</span>,</span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Date of birth"</span>,</span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Age at the time of taking office"</span>,</span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Vote registration number"</span>,</span>
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidate gender description"</span>,</span>
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Education level description"</span>,</span>
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Race code"</span>,</span>
<span id="cb11-21"><a href="#cb11-21" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Race description"</span>,</span>
<span id="cb11-22"><a href="#cb11-22" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Occupation code"</span>,</span>
<span id="cb11-23"><a href="#cb11-23" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Occupation description"</span>,</span>
<span id="cb11-24"><a href="#cb11-24" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Reelection status'</span>)</span>
<span id="cb11-25"><a href="#cb11-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-26"><a href="#cb11-26" aria-hidden="true" tabindex="-1"></a>code_book_3 <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(</span>
<span id="cb11-27"><a href="#cb11-27" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_name =</span> <span class="fu">names</span>(candidatos_sem_form),</span>
<span id="cb11-28"><a href="#cb11-28" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_class =</span> <span class="fu">sapply</span>(candidatos_sem_form, class),</span>
<span id="cb11-29"><a href="#cb11-29" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_desc =</span> descriptions_3)</span>
<span id="cb11-30"><a href="#cb11-30" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-31"><a href="#cb11-31" aria-hidden="true" tabindex="-1"></a>code_book_3</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["variable_name"],"name":[1],"type":["chr"],"align":["left"]},{"label":["variable_class"],"name":[2],"type":["chr"],"align":["left"]},{"label":["variable_desc"],"name":[3],"type":["chr"],"align":["left"]}],"data":[{"1":"ANO_ELEICAO","2":"integer","3":"Election year","_rn_":"ANO_ELEICAO"},{"1":"NM_UE","2":"character","3":"State name","_rn_":"NM_UE"},{"1":"SG_UF","2":"character","3":"State acronym","_rn_":"SG_UF"},{"1":"DS_CARGO_CONCORRIDO","2":"character","3":"Position description","_rn_":"DS_CARGO_CONCORRIDO"},{"1":"SG_PARTIDO","2":"character","3":"Party acronyn","_rn_":"SG_PARTIDO"},{"1":"NM_CANDIDATO","2":"character","3":"Candidate name","_rn_":"NM_CANDIDATO"},{"1":"NM_URNA_CANDIDATO","2":"character","3":"Candidate's ballot box name","_rn_":"NM_URNA_CANDIDATO"},{"1":"SQ_CANDIDATO","2":"numeric","3":"Candidate sequential ID","_rn_":"SQ_CANDIDATO"},{"1":"NR_CPF_CANDIDATO","2":"character","3":"Candidate ID","_rn_":"NR_CPF_CANDIDATO"},{"1":"DS_SITUACAO_CANDIDATURA","2":"character","3":"Candidacy status description","_rn_":"DS_SITUACAO_CANDIDATURA"},{"1":"DS_DETALHE_SITUACAO_CAND","2":"character","3":"Candidacy detailed status description","_rn_":"DS_DETALHE_SITUACAO_CAND"},{"1":"DS_SIT_TOT_TURNO","2":"character","3":"Vote tally status","_rn_":"DS_SIT_TOT_TURNO"},{"1":"DS_NACIONALIDADE","2":"character","3":"Nationality of the candidate","_rn_":"DS_NACIONALIDADE"},{"1":"SG_UF_NASCIMENTO","2":"character","3":"Acronym of place (state) of birth","_rn_":"SG_UF_NASCIMENTO"},{"1":"DT_NASCIMENTO","2":"character","3":"Date of birth","_rn_":"DT_NASCIMENTO"},{"1":"NR_IDADE_DATA_POSSE","2":"integer","3":"Age at the time of taking office","_rn_":"NR_IDADE_DATA_POSSE"},{"1":"NR_TITULO_ELEITORAL_CANDIDATO","2":"numeric","3":"Vote registration number","_rn_":"NR_TITULO_ELEITORAL_CANDIDATO"},{"1":"DS_GENERO","2":"character","3":"Candidate gender description","_rn_":"DS_GENERO"},{"1":"DS_GRAU_INSTRUCAO","2":"character","3":"Education level description","_rn_":"DS_GRAU_INSTRUCAO"},{"1":"CD_COR_RACA","2":"integer","3":"Race code","_rn_":"CD_COR_RACA"},{"1":"DS_COR_RACA","2":"character","3":"Race description","_rn_":"DS_COR_RACA"},{"1":"CD_OCUPACAO","2":"integer","3":"Occupation code","_rn_":"CD_OCUPACAO"},{"1":"DS_OCUPACAO","2":"character","3":"Occupation description","_rn_":"DS_OCUPACAO"},{"1":"ST_REELEICAO","2":"character","3":"Reelection status","_rn_":"ST_REELEICAO"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
<p>Save codebook 3</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(code_book_3, </span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>           <span class="st">'..//Dados//Code_Book_3.xlsx'</span>,</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a>           <span class="at">sheetName =</span> <span class="st">"codebook3"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
</section>
<section id="data-preparation-1" class="level2">
<h2 class="anchored" data-anchor-id="data-preparation-1">Data preparation</h2>
<section id="standardizing-variable-names" class="level3">
<h3 class="anchored" data-anchor-id="standardizing-variable-names">Standardizing variable names</h3>
<p>We made some changes to the names of the original TSE variables, as well as some aggregations and formatting to simplifly the analysis. Both the original and new names are kept in Brazilian Portuguese.</p>
<table class="table">
<colgroup>
<col style="width: 17%">
<col style="width: 17%">
<col style="width: 64%">
</colgroup>
<thead>
<tr class="header">
<th>Original name</th>
<th>New name</th>
<th>Other modifications</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>ANO_ELEICAO</td>
<td>ano_eleicao</td>
<td>–</td>
</tr>
<tr class="even">
<td>SG_UF</td>
<td>uf</td>
<td>–</td>
</tr>
<tr class="odd">
<td>DT_RECEITA</td>
<td>data_receita</td>
<td>Conversion to format dd/mm/aaaa</td>
</tr>
<tr class="even">
<td>DS_CARGO</td>
<td>cargo</td>
<td>–</td>
</tr>
<tr class="odd">
<td>DS_GENERO</td>
<td>genero</td>
<td>Removing blanking spaces</td>
</tr>
<tr class="even">
<td>DS_COR_RACA</td>
<td>cor_raca</td>
<td><p>If DS_COR_RACA = ‘PARDA’ or ‘PRETA’ then cor_raca = ‘Blak’</p>
<p>If DS_COR_RACA = ‘BRANCA’ then cor_raca = ‘White’</p>
<p>Else cor_raca = ‘Other races’</p></td>
</tr>
<tr class="odd">
<td>DS_SIT_TOT_TURNO</td>
<td>eleito</td>
<td><p>If DS_SIT_TURNO = ‘Eleito%’ then eleito = ‘Elected’</p>
<p>Else eleito = ‘Not elected’</p></td>
</tr>
<tr class="even">
<td>–</td>
<td>tipo_fonte_receita</td>
<td><p>If fonte_receita = ‘FUNDO ESPECIAL’ then tIpo_fonte_receita = ‘FEFC’</p>
<p>If fonte_receita = ‘FUNDO PARTIDARIO’ then tipo_fonte_receita = ‘FP’</p>
<p>Else tipo_fonte_receita = ‘Outros recursos’</p></td>
</tr>
<tr class="odd">
<td>DS_ESPECIE_RECEITA</td>
<td>especie_receita</td>
<td><p>If DS_ESPECIE_RECEITA = ‘Estimado’ então especie_receita = ‘Cash-equivalent’</p>
<p>Then especie_receita = ‘Cash’</p></td>
</tr>
</tbody>
</table>
</section>
<section id="standardizing-campaign-revenue-data-by-time" class="level3">
<h3 class="anchored" data-anchor-id="standardizing-campaign-revenue-data-by-time">Standardizing campaign revenue data by time</h3>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="co"># prepara dados de receitas para a análise</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>receitas_por_tempo <span class="ot">&lt;-</span> receitas_por_tempo_sem_form <span class="sc">%&gt;%</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">fonte_receita =</span> <span class="fu">str_to_upper</span>(DS_FONTE_RECEITA)) <span class="sc">%&gt;%</span></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">ano_eleicao =</span> <span class="fu">as.factor</span>(ANO_ELEICAO),</span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">cargo =</span> <span class="fu">str_to_upper</span>(DS_CARGO),</span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">uf =</span> <span class="fu">as.factor</span>(SG_UF),</span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a>    <span class="at">sq_candidato =</span> SQ_CANDIDATO,</span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">cpf_candidato =</span> <span class="fu">as.character</span>(NR_CPF_CANDIDATO),</span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">data_receita =</span> <span class="fu">as.Date</span>(DT_RECEITA, <span class="st">"%d/%m/%Y"</span>),</span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true" tabindex="-1"></a>    <span class="at">tipo_fonte_receita =</span> <span class="fu">case_when</span>(</span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true" tabindex="-1"></a>      fonte_receita <span class="sc">==</span> <span class="st">'FUNDO ESPECIAL'</span> <span class="sc">~</span> <span class="st">'FEFC'</span>,</span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true" tabindex="-1"></a>      fonte_receita <span class="sc">==</span> <span class="st">'FUNDO PARTIDARIO'</span> <span class="sc">~</span> <span class="st">'FP'</span>,</span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Outros recursos'</span></span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb13-16"><a href="#cb13-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">especie_receita =</span> <span class="fu">case_when</span>(</span>
<span id="cb13-17"><a href="#cb13-17" aria-hidden="true" tabindex="-1"></a>      DS_ESPECIE_RECEITA <span class="sc">==</span> <span class="st">'Estimado'</span> <span class="sc">~</span> <span class="st">'Cash-equivalent'</span>,</span>
<span id="cb13-18"><a href="#cb13-18" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Cash'</span>),</span>
<span id="cb13-19"><a href="#cb13-19" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receita_especie =</span> TOTAL_RECEITA</span>
<span id="cb13-20"><a href="#cb13-20" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb13-21"><a href="#cb13-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-22"><a href="#cb13-22" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(receitas_por_tempo_sem_form)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas_por_tempo)</code> lines standardized.</p>
</section>
<section id="standardizing-candidacies-data" class="level3">
<h3 class="anchored" data-anchor-id="standardizing-candidacies-data">Standardizing candidacies data</h3>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="co"># prepara dados de candidatos para a análise</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a>candidatos <span class="ot">&lt;-</span> candidatos_sem_form <span class="sc">%&gt;%</span></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(DS_SITUACAO_CANDIDATURA <span class="sc">==</span> <span class="st">"APTO"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">ano_eleicao =</span> <span class="fu">as.factor</span>(ANO_ELEICAO),</span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">uf =</span> <span class="fu">as.factor</span>(SG_UF),</span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">cargo =</span> <span class="fu">str_to_upper</span>(DS_CARGO_CONCORRIDO),</span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a>    <span class="at">partido =</span> SG_PARTIDO,</span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">cpf_candidato =</span> <span class="fu">as.character</span>(NR_CPF_CANDIDATO),</span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">sq_candidato =</span> SQ_CANDIDATO,</span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true" tabindex="-1"></a>    <span class="at">genero =</span> <span class="fu">case_when</span>(</span>
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO) <span class="sc">==</span> <span class="st">'FEMININO'</span> <span class="sc">~</span> <span class="st">'Women'</span>,</span>
<span id="cb14-13"><a href="#cb14-13" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO) <span class="sc">==</span> <span class="st">'MASCULINO'</span> <span class="sc">~</span> <span class="st">'Men'</span>,</span>
<span id="cb14-14"><a href="#cb14-14" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Others'</span></span>
<span id="cb14-15"><a href="#cb14-15" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb14-16"><a href="#cb14-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">cor_raca =</span> <span class="fu">case_when</span>(</span>
<span id="cb14-17"><a href="#cb14-17" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA <span class="sc">==</span> <span class="st">'PARDA'</span> <span class="sc">|</span> DS_COR_RACA <span class="sc">==</span> <span class="st">'PRETA'</span> <span class="sc">~</span> <span class="st">'Black'</span>,</span>
<span id="cb14-18"><a href="#cb14-18" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA <span class="sc">==</span> <span class="st">'BRANCA'</span> <span class="sc">~</span> <span class="st">'White'</span>,</span>
<span id="cb14-19"><a href="#cb14-19" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Other races'</span></span>
<span id="cb14-20"><a href="#cb14-20" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb14-21"><a href="#cb14-21" aria-hidden="true" tabindex="-1"></a>    <span class="at">eleito =</span> <span class="fu">case_when</span>(</span>
<span id="cb14-22"><a href="#cb14-22" aria-hidden="true" tabindex="-1"></a>      DS_SIT_TOT_TURNO <span class="sc">%like%</span> <span class="st">'ELEITO%'</span> <span class="sc">~</span> <span class="st">'Elected'</span>,</span>
<span id="cb14-23"><a href="#cb14-23" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Not elected'</span></span>
<span id="cb14-24"><a href="#cb14-24" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb14-25"><a href="#cb14-25" aria-hidden="true" tabindex="-1"></a>    <span class="at">reeleicao =</span> <span class="fu">case_when</span>(</span>
<span id="cb14-26"><a href="#cb14-26" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(ST_REELEICAO) <span class="sc">==</span> <span class="st">'N'</span> <span class="sc">~</span> <span class="st">'Challenger'</span>,</span>
<span id="cb14-27"><a href="#cb14-27" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Reelection'</span></span>
<span id="cb14-28"><a href="#cb14-28" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb14-29"><a href="#cb14-29" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb14-30"><a href="#cb14-30" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-31"><a href="#cb14-31" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(candidatos_sem_form)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(candidatos)</code> lines standardized.</p>
</section>
<section id="data-aggregation" class="level3">
<h3 class="anchored" data-anchor-id="data-aggregation">Data aggregation</h3>
<section id="step-1---combining-campaign-revenue-and-candidate-data" class="level4">
<h4 class="anchored" data-anchor-id="step-1---combining-campaign-revenue-and-candidate-data">Step 1 - Combining campaign revenue and candidate data</h4>
<p>In this step, we join revenue and candidacies data to calculate the proportion of candidates. This is necessary because not all candidates necessarily submit financial statements, as they may have their candidacy registration denied or even withdraw their candidacy.</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>receitas_candidatos_por_tempo <span class="ot">&lt;-</span> candidatos <span class="sc">%&gt;%</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a>    ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>), </span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a>    cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO DISTRITAL'</span>, </span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO ESTADUAL'</span>, </span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO FEDERAL'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(</span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a>    ano_eleicao, </span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a>    uf, </span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true" tabindex="-1"></a>    cargo, </span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true" tabindex="-1"></a>    partido, </span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true" tabindex="-1"></a>    sq_candidato,</span>
<span id="cb15-13"><a href="#cb15-13" aria-hidden="true" tabindex="-1"></a>    cpf_candidato, </span>
<span id="cb15-14"><a href="#cb15-14" aria-hidden="true" tabindex="-1"></a>    genero, </span>
<span id="cb15-15"><a href="#cb15-15" aria-hidden="true" tabindex="-1"></a>    cor_raca,</span>
<span id="cb15-16"><a href="#cb15-16" aria-hidden="true" tabindex="-1"></a>    eleito,</span>
<span id="cb15-17"><a href="#cb15-17" aria-hidden="true" tabindex="-1"></a>    reeleicao) <span class="sc">%&gt;%</span> </span>
<span id="cb15-18"><a href="#cb15-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(</span>
<span id="cb15-19"><a href="#cb15-19" aria-hidden="true" tabindex="-1"></a>    receitas_por_tempo,</span>
<span id="cb15-20"><a href="#cb15-20" aria-hidden="true" tabindex="-1"></a>    <span class="at">by =</span> <span class="fu">c</span>(<span class="st">'ano_eleicao'</span>, <span class="st">'cargo'</span>, <span class="st">'uf'</span>, <span class="st">'sq_candidato'</span>, <span class="st">'cpf_candidato'</span>),</span>
<span id="cb15-21"><a href="#cb15-21" aria-hidden="true" tabindex="-1"></a>    <span class="at">suffix =</span> <span class="fu">c</span>(<span class="st">""</span>, <span class="st">".y"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb15-22"><a href="#cb15-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span><span class="fu">ends_with</span>(<span class="st">".y"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb15-23"><a href="#cb15-23" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(</span>
<span id="cb15-24"><a href="#cb15-24" aria-hidden="true" tabindex="-1"></a>    ano_eleicao,</span>
<span id="cb15-25"><a href="#cb15-25" aria-hidden="true" tabindex="-1"></a>    uf,</span>
<span id="cb15-26"><a href="#cb15-26" aria-hidden="true" tabindex="-1"></a>    cargo, </span>
<span id="cb15-27"><a href="#cb15-27" aria-hidden="true" tabindex="-1"></a>    partido,</span>
<span id="cb15-28"><a href="#cb15-28" aria-hidden="true" tabindex="-1"></a>    sq_candidato,</span>
<span id="cb15-29"><a href="#cb15-29" aria-hidden="true" tabindex="-1"></a>    cpf_candidato, </span>
<span id="cb15-30"><a href="#cb15-30" aria-hidden="true" tabindex="-1"></a>    genero, </span>
<span id="cb15-31"><a href="#cb15-31" aria-hidden="true" tabindex="-1"></a>    cor_raca, </span>
<span id="cb15-32"><a href="#cb15-32" aria-hidden="true" tabindex="-1"></a>    eleito,</span>
<span id="cb15-33"><a href="#cb15-33" aria-hidden="true" tabindex="-1"></a>    reeleicao,</span>
<span id="cb15-34"><a href="#cb15-34" aria-hidden="true" tabindex="-1"></a>    fonte_receita,</span>
<span id="cb15-35"><a href="#cb15-35" aria-hidden="true" tabindex="-1"></a>    data_receita,</span>
<span id="cb15-36"><a href="#cb15-36" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita,</span>
<span id="cb15-37"><a href="#cb15-37" aria-hidden="true" tabindex="-1"></a>    especie_receita,</span>
<span id="cb15-38"><a href="#cb15-38" aria-hidden="true" tabindex="-1"></a>    total_receita_especie</span>
<span id="cb15-39"><a href="#cb15-39" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">%&gt;%</span></span>
<span id="cb15-40"><a href="#cb15-40" aria-hidden="true" tabindex="-1"></a>  <span class="fu">na.omit</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas_candidatos_por_tempo)</code> lines generated.</p>
</section>
<section id="step-2---selects-and-aggregates-public-revenue-data-by-gender-and-race" class="level4">
<h4 class="anchored" data-anchor-id="step-2---selects-and-aggregates-public-revenue-data-by-gender-and-race">Step 2 - Selects and aggregates public revenue data by gender and race</h4>
<p>In this step, we aggregate public revenue data from both the 2018 and 2020 General Elections by gender and race.</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="co"># applies monetary correction factor: 2018-october =&gt; 2022-october</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a>fator_correcao <span class="ot">&lt;-</span> <span class="fl">1.63171680</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a>receitas_publicas <span class="ot">&lt;-</span> receitas_candidatos_por_tempo <span class="sc">%&gt;%</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a>    ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>), </span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a>    cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO DISTRITAL'</span>, </span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO ESTADUAL'</span>, </span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO FEDERAL'</span>),</span>
<span id="cb16-10"><a href="#cb16-10" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'FEFC'</span>, <span class="st">'FP'</span>),</span>
<span id="cb16-11"><a href="#cb16-11" aria-hidden="true" tabindex="-1"></a>    total_receita_especie <span class="sc">&lt;</span> <span class="fl">20000002.89</span>) <span class="sc">%&gt;%</span> <span class="co"># exclui entrada outlier</span></span>
<span id="cb16-12"><a href="#cb16-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb16-13"><a href="#cb16-13" aria-hidden="true" tabindex="-1"></a>    <span class="at">receita =</span> <span class="fu">ifelse</span>(</span>
<span id="cb16-14"><a href="#cb16-14" aria-hidden="true" tabindex="-1"></a>      ano_eleicao <span class="sc">==</span> <span class="dv">2018</span>, </span>
<span id="cb16-15"><a href="#cb16-15" aria-hidden="true" tabindex="-1"></a>      total_receita_especie <span class="sc">*</span> fator_correcao, </span>
<span id="cb16-16"><a href="#cb16-16" aria-hidden="true" tabindex="-1"></a>      total_receita_especie)) <span class="sc">%&gt;%</span></span>
<span id="cb16-17"><a href="#cb16-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(</span>
<span id="cb16-18"><a href="#cb16-18" aria-hidden="true" tabindex="-1"></a>    ano_eleicao,</span>
<span id="cb16-19"><a href="#cb16-19" aria-hidden="true" tabindex="-1"></a>    uf,</span>
<span id="cb16-20"><a href="#cb16-20" aria-hidden="true" tabindex="-1"></a>    genero,</span>
<span id="cb16-21"><a href="#cb16-21" aria-hidden="true" tabindex="-1"></a>    cor_raca,</span>
<span id="cb16-22"><a href="#cb16-22" aria-hidden="true" tabindex="-1"></a>    eleito,</span>
<span id="cb16-23"><a href="#cb16-23" aria-hidden="true" tabindex="-1"></a>    cargo,</span>
<span id="cb16-24"><a href="#cb16-24" aria-hidden="true" tabindex="-1"></a>    reeleicao,</span>
<span id="cb16-25"><a href="#cb16-25" aria-hidden="true" tabindex="-1"></a>    partido,</span>
<span id="cb16-26"><a href="#cb16-26" aria-hidden="true" tabindex="-1"></a>    cpf_candidato,</span>
<span id="cb16-27"><a href="#cb16-27" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita) <span class="sc">%&gt;%</span></span>
<span id="cb16-28"><a href="#cb16-28" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(</span>
<span id="cb16-29"><a href="#cb16-29" aria-hidden="true" tabindex="-1"></a>    <span class="at">rec_cand =</span> <span class="fu">sum</span>(total_receita_especie), </span>
<span id="cb16-30"><a href="#cb16-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">na.rm =</span> <span class="cn">TRUE</span>) <span class="sc">%&gt;%</span></span>
<span id="cb16-31"><a href="#cb16-31" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(ano_eleicao, cargo, uf, genero, cor_raca)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas_publicas)</code> lines generated.</p>
</section>
<section id="step-3---selects-and-aggregates-public-revenue-data-by-source-and-week" class="level4">
<h4 class="anchored" data-anchor-id="step-3---selects-and-aggregates-public-revenue-data-by-source-and-week">Step 3 - Selects and aggregates public revenue data by source and week</h4>
<p>In this step, we aggregate public revenue data from both the 2018 and 2020 General Elections by source and week.</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>receitas_publicas_semana <span class="ot">&lt;-</span> receitas_candidatos_por_tempo <span class="sc">%&gt;%</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a>    ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>), </span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a>    cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO DISTRITAL'</span>, </span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO ESTADUAL'</span>, </span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO FEDERAL'</span>),</span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'FEFC'</span>, <span class="st">'FP'</span>),</span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true" tabindex="-1"></a>    total_receita_especie <span class="sc">&lt;</span> <span class="fl">20000002.89</span>) <span class="sc">%&gt;%</span> <span class="co"># exclui entrada outlier</span></span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">receita =</span> <span class="fu">ifelse</span>(</span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true" tabindex="-1"></a>      ano_eleicao <span class="sc">==</span> <span class="dv">2018</span>, </span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true" tabindex="-1"></a>      total_receita_especie <span class="sc">*</span> fator_correcao, </span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true" tabindex="-1"></a>      total_receita_especie),</span>
<span id="cb17-14"><a href="#cb17-14" aria-hidden="true" tabindex="-1"></a>    <span class="at">semana_receita =</span> <span class="fu">as.Date</span>(</span>
<span id="cb17-15"><a href="#cb17-15" aria-hidden="true" tabindex="-1"></a>      <span class="fu">cut</span>(data_receita, <span class="at">breaks =</span> <span class="st">'week'</span>, </span>
<span id="cb17-16"><a href="#cb17-16" aria-hidden="true" tabindex="-1"></a>          <span class="at">start.on.monday =</span> <span class="cn">FALSE</span>)),) <span class="sc">%&gt;%</span></span>
<span id="cb17-17"><a href="#cb17-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(</span>
<span id="cb17-18"><a href="#cb17-18" aria-hidden="true" tabindex="-1"></a>    ano_eleicao,</span>
<span id="cb17-19"><a href="#cb17-19" aria-hidden="true" tabindex="-1"></a>    uf,</span>
<span id="cb17-20"><a href="#cb17-20" aria-hidden="true" tabindex="-1"></a>    genero,</span>
<span id="cb17-21"><a href="#cb17-21" aria-hidden="true" tabindex="-1"></a>    cor_raca,</span>
<span id="cb17-22"><a href="#cb17-22" aria-hidden="true" tabindex="-1"></a>    eleito,</span>
<span id="cb17-23"><a href="#cb17-23" aria-hidden="true" tabindex="-1"></a>    cargo,</span>
<span id="cb17-24"><a href="#cb17-24" aria-hidden="true" tabindex="-1"></a>    reeleicao,</span>
<span id="cb17-25"><a href="#cb17-25" aria-hidden="true" tabindex="-1"></a>    partido,</span>
<span id="cb17-26"><a href="#cb17-26" aria-hidden="true" tabindex="-1"></a>    cpf_candidato,</span>
<span id="cb17-27"><a href="#cb17-27" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita,</span>
<span id="cb17-28"><a href="#cb17-28" aria-hidden="true" tabindex="-1"></a>    semana_receita) <span class="sc">%&gt;%</span></span>
<span id="cb17-29"><a href="#cb17-29" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">rec_cand =</span> <span class="fu">sum</span>(total_receita_especie))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas_publicas_semana)</code> lines generated.</p>
</section>
<section id="step-4---filter-only-public-revenue-data-and-aggregate-them-by-source-kind-and-week" class="level4">
<h4 class="anchored" data-anchor-id="step-4---filter-only-public-revenue-data-and-aggregate-them-by-source-kind-and-week">Step 4 - Filter only public revenue data and aggregate them by source, kind and week</h4>
<p>In this step, we aggregate public revenue data from both the 2018 and 2020 Brazilian General Elections by source and kind of campaign revenue.</p>
<p>Candidate level data</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>receitas_publicas_especie <span class="ot">&lt;-</span> receitas_candidatos_por_tempo <span class="sc">%&gt;%</span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a>    ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>), </span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a>    cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO DISTRITAL'</span>, </span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO ESTADUAL'</span>, </span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO FEDERAL'</span>),</span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'FEFC'</span>, <span class="st">'FP'</span>),</span>
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a>    total_receita_especie <span class="sc">&lt;</span> <span class="fl">20000002.89</span>) <span class="sc">%&gt;%</span> <span class="co"># exclui entrada outlier</span></span>
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">receita =</span> <span class="fu">ifelse</span>(</span>
<span id="cb18-11"><a href="#cb18-11" aria-hidden="true" tabindex="-1"></a>      ano_eleicao <span class="sc">==</span> <span class="dv">2018</span>, </span>
<span id="cb18-12"><a href="#cb18-12" aria-hidden="true" tabindex="-1"></a>      total_receita_especie <span class="sc">*</span> fator_correcao, </span>
<span id="cb18-13"><a href="#cb18-13" aria-hidden="true" tabindex="-1"></a>      total_receita_especie)) <span class="sc">%&gt;%</span></span>
<span id="cb18-14"><a href="#cb18-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(</span>
<span id="cb18-15"><a href="#cb18-15" aria-hidden="true" tabindex="-1"></a>    ano_eleicao,</span>
<span id="cb18-16"><a href="#cb18-16" aria-hidden="true" tabindex="-1"></a>    uf,</span>
<span id="cb18-17"><a href="#cb18-17" aria-hidden="true" tabindex="-1"></a>    genero,</span>
<span id="cb18-18"><a href="#cb18-18" aria-hidden="true" tabindex="-1"></a>    cor_raca,</span>
<span id="cb18-19"><a href="#cb18-19" aria-hidden="true" tabindex="-1"></a>    eleito,</span>
<span id="cb18-20"><a href="#cb18-20" aria-hidden="true" tabindex="-1"></a>    cargo,</span>
<span id="cb18-21"><a href="#cb18-21" aria-hidden="true" tabindex="-1"></a>    reeleicao,</span>
<span id="cb18-22"><a href="#cb18-22" aria-hidden="true" tabindex="-1"></a>    partido,</span>
<span id="cb18-23"><a href="#cb18-23" aria-hidden="true" tabindex="-1"></a>    cpf_candidato,</span>
<span id="cb18-24"><a href="#cb18-24" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita,</span>
<span id="cb18-25"><a href="#cb18-25" aria-hidden="true" tabindex="-1"></a>    especie_receita) <span class="sc">%&gt;%</span></span>
<span id="cb18-26"><a href="#cb18-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">rec_cand =</span> <span class="fu">sum</span>(total_receita_especie))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas_publicas_especie)</code> lines generated.</p>
<p>Kind of revenue level data</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="co"># agrega receitas públicas por eleição, gênero, cor/raça e espécie</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>receitas_publicas_especie_agr <span class="ot">&lt;-</span> receitas_publicas_especie <span class="sc">%&gt;%</span></span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">cargo =</span> <span class="fu">ifelse</span>(cargo <span class="sc">==</span> <span class="st">"DEPUTADO DISTRITAL"</span>, </span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a>                        <span class="st">"DEPUTADO ESTADUAL"</span>, </span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a>                        cargo)) <span class="sc">%&gt;%</span></span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, cargo, genero, cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_rec_ano_cargo_genero_cor =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb19-8"><a href="#cb19-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb19-9"><a href="#cb19-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, cargo, genero, cor_raca, especie_receita) <span class="sc">%&gt;%</span></span>
<span id="cb19-10"><a href="#cb19-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(</span>
<span id="cb19-11"><a href="#cb19-11" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_rec_ano_cargo_genero_cor_especie =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>), </span>
<span id="cb19-12"><a href="#cb19-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">perc_rec_ano_cargo_genero_cor_especie =</span> total_rec_ano_cargo_genero_cor_especie <span class="sc">/</span> <span class="fu">max</span>(total_rec_ano_cargo_genero_cor),</span>
<span id="cb19-13"><a href="#cb19-13" aria-hidden="true" tabindex="-1"></a>    <span class="at">.groups =</span> <span class="st">"drop"</span></span>
<span id="cb19-14"><a href="#cb19-14" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">%&gt;%</span></span>
<span id="cb19-15"><a href="#cb19-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(ano_eleicao, cargo, genero, especie_receita, cor_raca)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas_publicas_especie_agr)</code> lines generated.</p>
</section>
<section id="step-5---aggregate-public-revenues-by-election-week-gender-and-race---federal-deputy-candidates" class="level4">
<h4 class="anchored" data-anchor-id="step-5---aggregate-public-revenues-by-election-week-gender-and-race---federal-deputy-candidates">Step 5 - Aggregate public revenues by election, week, gender and race - federal deputy candidates</h4>
<p>In this step, we aggregate public revenue data from both the 2018 and 2020 Brazilian General Elections by year of election, week, gender and race, for federal deputy candidates.</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>receitas_publicas_semana_dep_fed <span class="ot">&lt;-</span> receitas_publicas_semana <span class="sc">%&gt;%</span></span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(cargo <span class="sc">==</span> <span class="st">'DEPUTADO FEDERAL'</span>) <span class="sc">%&gt;%</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao) <span class="sc">%&gt;%</span></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_cand_ano =</span> <span class="fu">n_distinct</span>(cpf_candidato)) <span class="sc">%&gt;%</span></span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, genero, cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_cand_cor =</span> <span class="fu">n_distinct</span>(cpf_candidato)) <span class="sc">%&gt;%</span></span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, semana_receita) <span class="sc">%&gt;%</span></span>
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receitas_semana =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">media_receitas_semana =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>) <span class="sc">/</span> total_cand_ano) <span class="sc">%&gt;%</span></span>
<span id="cb20-13"><a href="#cb20-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb20-14"><a href="#cb20-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, semana_receita, genero, cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb20-15"><a href="#cb20-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb20-16"><a href="#cb20-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receitas_cor =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb20-17"><a href="#cb20-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">media_receitas_genero_cor =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>) <span class="sc">/</span> total_cand_cor) <span class="sc">%&gt;%</span></span>
<span id="cb20-18"><a href="#cb20-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb20-19"><a href="#cb20-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(ano_eleicao, semana_receita, genero, cor_raca)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas_publicas_semana_dep_fed)</code> lines generated (federal deputy).</p>
</section>
<section id="step-6---aggregate-public-revenues-per-week---state-deputy-candidates" class="level4">
<h4 class="anchored" data-anchor-id="step-6---aggregate-public-revenues-per-week---state-deputy-candidates">Step 6 - Aggregate public revenues per week - state deputy candidates</h4>
<p>In this step, we aggregate public revenue data from both the 2018 and 2020 Brazilian General Elections by year of election, week, gender and race, for state deputy candidates.</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="co"># agrega receitas públicas por eleição, semana, gênero, cor/raça e situaçao de reeleição</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>receitas_publicas_semana_dep_est <span class="ot">&lt;-</span> receitas_publicas_semana <span class="sc">%&gt;%</span></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO DISTRITAL'</span>, <span class="st">'DEPUTADO ESTADUAL'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao) <span class="sc">%&gt;%</span></span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_cand_ano =</span> <span class="fu">n_distinct</span>(cpf_candidato)) <span class="sc">%&gt;%</span></span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, genero, cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_cand_cor =</span> <span class="fu">n_distinct</span>(cpf_candidato)) <span class="sc">%&gt;%</span></span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, semana_receita) <span class="sc">%&gt;%</span></span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receitas_semana =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true" tabindex="-1"></a>    <span class="at">media_receitas_semana =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>) <span class="sc">/</span> total_cand_ano) <span class="sc">%&gt;%</span></span>
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb21-15"><a href="#cb21-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, semana_receita, genero, cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb21-16"><a href="#cb21-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb21-17"><a href="#cb21-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receitas_cor =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb21-18"><a href="#cb21-18" aria-hidden="true" tabindex="-1"></a>    <span class="at">media_receitas_genero_cor =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>) <span class="sc">/</span> total_cand_cor) <span class="sc">%&gt;%</span></span>
<span id="cb21-19"><a href="#cb21-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb21-20"><a href="#cb21-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(ano_eleicao, semana_receita, genero, cor_raca)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>⟶ <code>{r} nrow(receitas_publicas_semana_dep_est)</code> lines generated (state deputy).</p>
</section>
<section id="step-7---calculate-minimum-and-maximum-values-of-public-revenue" class="level4">
<h4 class="anchored" data-anchor-id="step-7---calculate-minimum-and-maximum-values-of-public-revenue">Step 7 - Calculate minimum and maximum values of public revenue</h4>
<p>In this step, we identify both the minimum and maximum values of public revenue values and the minimum and maximum dates for constructing the graph scales.</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>sum_receitas <span class="ot">&lt;-</span> <span class="fu">aggregate</span>(</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>  rec_cand <span class="sc">~</span> ano_eleicao <span class="sc">+</span> genero <span class="sc">+</span> semana_receita, </span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> receitas_publicas_semana, sum)</span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a>sum_receitas <span class="ot">&lt;-</span> <span class="fu">tibble</span>(sum_receitas) <span class="sc">%&gt;%</span></span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(ano_eleicao, genero, semana_receita)</span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a>max_receita <span class="ot">&lt;-</span> <span class="fu">max</span>(sum_receitas<span class="sc">$</span>rec_cand)</span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a><span class="co"># foram usadas as datas da convenção partidária</span></span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a>min_data_convencao_2018 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"2018-07-20"</span>, <span class="st">"2018-10-06"</span>)</span>
<span id="cb22-10"><a href="#cb22-10" aria-hidden="true" tabindex="-1"></a>min_data_convencao_2022 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"2022-07-20"</span>, <span class="st">"2022-10-01"</span>)</span>
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true" tabindex="-1"></a>min_data_campanha_2018 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"2018-08-13"</span>, <span class="st">"2018-10-06"</span>)</span>
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true" tabindex="-1"></a>min_data_campanha_2022 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"2022-08-16"</span>, <span class="st">"2022-10-01"</span>)</span>
<span id="cb22-13"><a href="#cb22-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-14"><a href="#cb22-14" aria-hidden="true" tabindex="-1"></a><span class="co"># funçao para gravar uma figura em alta resoluçao</span></span>
<span id="cb22-15"><a href="#cb22-15" aria-hidden="true" tabindex="-1"></a>grava_figura <span class="ot">&lt;-</span> <span class="cf">function</span>(nome, formato) {</span>
<span id="cb22-16"><a href="#cb22-16" aria-hidden="true" tabindex="-1"></a>  Cairo<span class="sc">::</span><span class="fu">Cairo</span>(</span>
<span id="cb22-17"><a href="#cb22-17" aria-hidden="true" tabindex="-1"></a>    <span class="dv">30</span>,</span>
<span id="cb22-18"><a href="#cb22-18" aria-hidden="true" tabindex="-1"></a>    <span class="dv">20</span>,</span>
<span id="cb22-19"><a href="#cb22-19" aria-hidden="true" tabindex="-1"></a>    <span class="at">file =</span> <span class="fu">paste</span>(nome, formato, <span class="at">sep =</span> <span class="st">"."</span>),</span>
<span id="cb22-20"><a href="#cb22-20" aria-hidden="true" tabindex="-1"></a>    <span class="at">type =</span> formato,</span>
<span id="cb22-21"><a href="#cb22-21" aria-hidden="true" tabindex="-1"></a>    <span class="at">bg =</span> <span class="st">"transparent"</span>,</span>
<span id="cb22-22"><a href="#cb22-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">dpi =</span> <span class="dv">600</span>,</span>
<span id="cb22-23"><a href="#cb22-23" aria-hidden="true" tabindex="-1"></a>    <span class="at">units =</span> <span class="st">"cm"</span></span>
<span id="cb22-24"><a href="#cb22-24" aria-hidden="true" tabindex="-1"></a>  )  </span>
<span id="cb22-25"><a href="#cb22-25" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<ul>
<li><p>Maximum public revenue value for a single week = <code>{r} max_receita</code></p></li>
<li><p>Convention date for 2018 Election = <code>{r} min_data_convencao_2018</code></p></li>
<li><p>Convention date for 2022 Election = <code>{r} min_data_convencao_2022</code></p></li>
</ul>
</section>
</section>
</section>
</section>
<section id="data-analysis" class="level1">
<h1>Data Analysis</h1>
<section id="preliminary-analysis---total-resources-transfers-between-candidate-providers-by-resource-type" class="level2">
<h2 class="anchored" data-anchor-id="preliminary-analysis---total-resources-transfers-between-candidate-providers-by-resource-type">Preliminary Analysis - total resources transfers between candidate providers, by resource type</h2>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>receitas <span class="sc">%&gt;%</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2022</span>,</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a>         NR_CPF_CNPJ_DOADOR <span class="sc">!=</span> NR_CNPJ_PRESTADOR_CONTA,</span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a>         DS_FONTE_RECURSO <span class="sc">%in%</span> </span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a>           <span class="fu">c</span>(<span class="st">'Recursos de outros candidatos'</span>, </span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a>             <span class="st">'Recursos de partido político'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(tipo_recurso) <span class="sc">%&gt;%</span></span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">transferencias_entre_prestadores =</span> <span class="fu">sum</span>(TOTAL_RECEITA),</span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true" tabindex="-1"></a>            <span class="at">.groups =</span> <span class="st">'drop'</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":["tipo_recurso"],"name":[1],"type":["chr"],"align":["left"]},{"label":["transferencias_entre_prestadores"],"name":[2],"type":["dbl"],"align":["right"]}],"data":[{"1":"Private","2":"191798623"},{"1":"Public","2":"5400226457"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
</section>
<section id="distribution-of-cash-equivalent-and-cash-funding" class="level2">
<h2 class="anchored" data-anchor-id="distribution-of-cash-equivalent-and-cash-funding"><strong>Distribution of Cash-Equivalent and Cash Funding</strong></h2>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>In this work, we consider only funding originating from public revenue.</p>
</div>
</div>
<section id="graph-1---proportion-of-cash-equivalent-funds-of-candidates-for-federal-deputy-by-race-and-gender" class="level3">
<h3 class="anchored" data-anchor-id="graph-1---proportion-of-cash-equivalent-funds-of-candidates-for-federal-deputy-by-race-and-gender">Graph 1 - Proportion of cash-equivalent funds of candidates for federal deputy, by race and gender</h3>
<p>Create data object</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>g1_data <span class="ot">&lt;-</span> receitas_publicas_especie_agr <span class="sc">%&gt;%</span> </span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a>    <span class="fu">filter</span>(</span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a>      ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>),</span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a>      cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>),</span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a>      cargo <span class="sc">==</span> <span class="st">'DEPUTADO FEDERAL'</span>,</span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true" tabindex="-1"></a>      especie_receita <span class="sc">==</span> <span class="st">'Cash-equivalent'</span>) <span class="sc">%&gt;%</span></span>
<span id="cb24-7"><a href="#cb24-7" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(</span>
<span id="cb24-8"><a href="#cb24-8" aria-hidden="true" tabindex="-1"></a>      <span class="at">ano_eleicao =</span> <span class="fu">as.factor</span>(ano_eleicao),</span>
<span id="cb24-9"><a href="#cb24-9" aria-hidden="true" tabindex="-1"></a>      <span class="at">cor_raca =</span> <span class="fu">factor</span>(cor_raca, <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>))</span>
<span id="cb24-10"><a href="#cb24-10" aria-hidden="true" tabindex="-1"></a>  )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>Plot figure</p>
<div class="cell output">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="co"># identifies the minimum and maximum revenue, as well as the minimum and maximum dates to build the chart scale</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a>max_receita <span class="ot">&lt;-</span> <span class="fu">max</span>(g1_data<span class="sc">$</span>perc_rec_ano_cargo_genero_cor_especie)</span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a><span class="co">#limites &lt;- c(0, max_receita) * 2</span></span>
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a><span class="co">#quebras &lt;- round(seq(limites[1], limites[2], by = max_receita / 10), </span></span>
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true" tabindex="-1"></a><span class="co">#                 digits = 2)</span></span>
<span id="cb25-7"><a href="#cb25-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-8"><a href="#cb25-8" aria-hidden="true" tabindex="-1"></a><span class="co"># 2018 and 2022</span></span>
<span id="cb25-9"><a href="#cb25-9" aria-hidden="true" tabindex="-1"></a>g1_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb25-10"><a href="#cb25-10" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g1_data, </span>
<span id="cb25-11"><a href="#cb25-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(<span class="at">fill =</span> genero, </span>
<span id="cb25-12"><a href="#cb25-12" aria-hidden="true" tabindex="-1"></a>      <span class="at">x =</span> <span class="fu">as.factor</span>(cor_raca), </span>
<span id="cb25-13"><a href="#cb25-13" aria-hidden="true" tabindex="-1"></a>      <span class="at">y =</span> perc_rec_ano_cargo_genero_cor_especie)) <span class="sc">+</span></span>
<span id="cb25-14"><a href="#cb25-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb25-15"><a href="#cb25-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb25-16"><a href="#cb25-16" aria-hidden="true" tabindex="-1"></a>    <span class="fu">aes</span>(<span class="at">label=</span>scales<span class="sc">:::</span><span class="fu">percent</span>(perc_rec_ano_cargo_genero_cor_especie, <span class="at">accuracy=</span><span class="fl">0.1</span>)), <span class="at">position=</span><span class="fu">position_dodge</span>(<span class="at">width =</span> <span class="fl">0.9</span>), </span>
<span id="cb25-17"><a href="#cb25-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust=</span> <span class="sc">-</span><span class="fl">0.5</span>, </span>
<span id="cb25-18"><a href="#cb25-18" aria-hidden="true" tabindex="-1"></a>    <span class="at">size=</span> <span class="dv">4</span></span>
<span id="cb25-19"><a href="#cb25-19" aria-hidden="true" tabindex="-1"></a>    )<span class="sc">+</span></span>
<span id="cb25-20"><a href="#cb25-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">facet_wrap</span>(<span class="sc">~</span>ano_eleicao) <span class="sc">+</span></span>
<span id="cb25-21"><a href="#cb25-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb25-22"><a href="#cb25-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_fill_brewer</span>(<span class="at">palette =</span> <span class="st">"Set1"</span>) <span class="sc">+</span></span>
<span id="cb25-23"><a href="#cb25-23" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb25-24"><a href="#cb25-24" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span>percent,</span>
<span id="cb25-25"><a href="#cb25-25" aria-hidden="true" tabindex="-1"></a>   <span class="co"># limits = limites,</span></span>
<span id="cb25-26"><a href="#cb25-26" aria-hidden="true" tabindex="-1"></a>  <span class="co">#  breaks = quebras) +</span></span>
<span id="cb25-27"><a href="#cb25-27" aria-hidden="true" tabindex="-1"></a>     <span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="fl">0.10</span>), <span class="co">#0% a 10%</span></span>
<span id="cb25-28"><a href="#cb25-28" aria-hidden="true" tabindex="-1"></a>      <span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="fl">0.10</span>, <span class="at">by =</span> <span class="fl">0.02</span>)) <span class="sc">+</span></span>
<span id="cb25-29"><a href="#cb25-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-30"><a href="#cb25-30" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb25-31"><a href="#cb25-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Race/color"</span>, </span>
<span id="cb25-32"><a href="#cb25-32" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Proportion of cash-equivalent funding (%)"</span>) <span class="sc">+</span></span>
<span id="cb25-33"><a href="#cb25-33" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb25-34"><a href="#cb25-34" aria-hidden="true" tabindex="-1"></a>  <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb25-35"><a href="#cb25-35" aria-hidden="true" tabindex="-1"></a>    <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb25-36"><a href="#cb25-36" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">14</span>), </span>
<span id="cb25-37"><a href="#cb25-37" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">14</span>), </span>
<span id="cb25-38"><a href="#cb25-38" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>), </span>
<span id="cb25-39"><a href="#cb25-39" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>), </span>
<span id="cb25-40"><a href="#cb25-40" aria-hidden="true" tabindex="-1"></a>    <span class="at">strip.text =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>),    </span>
<span id="cb25-41"><a href="#cb25-41" aria-hidden="true" tabindex="-1"></a>    <span class="at">legend.title =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb25-42"><a href="#cb25-42" aria-hidden="true" tabindex="-1"></a>    <span class="at">legend.text =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>)) </span>
<span id="cb25-43"><a href="#cb25-43" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-44"><a href="#cb25-44" aria-hidden="true" tabindex="-1"></a>g1_figure</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">
<div id="fig-1" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<p><img src="artigo-rbcp-2025_EN_files/figure-html/fig-1-1.png" class="img-fluid figure-img" alt="Proportion of cash-equivalent funding of candidates to federal deputy, in 2018 and 2022, by gender and race" width="768"></p>
<figcaption class="figure-caption">Figure&nbsp;1: Proportion of cash-equivalent funding of candidates to federal deputy, in 2018 and 2022, by gender and race</figcaption>
</figure>
</div>
</div>
</div>
<p>Save figure</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="fu">grava_figura</span>(<span class="st">"..//Figuras//paper-fig-1"</span>, <span class="st">"png"</span>)</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a>g1_figure</span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a><span class="fu">dev.off</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>png 
  2 </code></pre>
</div>
</div>
</section>
<section id="graph-2---proportion-of-cash-equivalent-funds-of-candidates-for-state-deputy-by-race-and-gender" class="level3">
<h3 class="anchored" data-anchor-id="graph-2---proportion-of-cash-equivalent-funds-of-candidates-for-state-deputy-by-race-and-gender">Graph 2 - Proportion of cash-equivalent funds of candidates for state deputy, by race and gender</h3>
<p>Create data object</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a>g2_data <span class="ot">&lt;-</span> receitas_publicas_especie_agr <span class="sc">%&gt;%</span> </span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a>    <span class="fu">filter</span>(</span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a>      ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>),</span>
<span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a>      cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>),</span>
<span id="cb28-5"><a href="#cb28-5" aria-hidden="true" tabindex="-1"></a>      cargo <span class="sc">==</span> <span class="st">"DEPUTADO ESTADUAL"</span>,</span>
<span id="cb28-6"><a href="#cb28-6" aria-hidden="true" tabindex="-1"></a>      especie_receita <span class="sc">==</span> <span class="st">"Cash-equivalent"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb28-7"><a href="#cb28-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb28-8"><a href="#cb28-8" aria-hidden="true" tabindex="-1"></a>    <span class="at">ano_eleicao =</span> <span class="fu">as.factor</span>(ano_eleicao),</span>
<span id="cb28-9"><a href="#cb28-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">cor_raca =</span> <span class="fu">factor</span>(cor_raca, <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>))</span>
<span id="cb28-10"><a href="#cb28-10" aria-hidden="true" tabindex="-1"></a>  )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>Plot figure</p>
<div class="cell output">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="co"># identifies the minimum and maximum revenue, as well as the minimum and maximum dates to build the chart scale</span></span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a>max_receita <span class="ot">&lt;-</span> <span class="fu">max</span>(g2_data<span class="sc">$</span>perc_rec_ano_cargo_genero_cor_especie)</span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a>limites <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">0</span>, max_receita) <span class="sc">*</span> <span class="fl">1.01</span></span>
<span id="cb29-5"><a href="#cb29-5" aria-hidden="true" tabindex="-1"></a>quebras <span class="ot">&lt;-</span> <span class="fu">seq</span>(limites[<span class="dv">1</span>], limites[<span class="dv">2</span>], <span class="at">by =</span> max_receita <span class="sc">/</span> <span class="dv">10</span>)</span>
<span id="cb29-6"><a href="#cb29-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb29-7"><a href="#cb29-7" aria-hidden="true" tabindex="-1"></a><span class="co"># 2018 and 2022</span></span>
<span id="cb29-8"><a href="#cb29-8" aria-hidden="true" tabindex="-1"></a>g2_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb29-9"><a href="#cb29-9" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g2_data, </span>
<span id="cb29-10"><a href="#cb29-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(<span class="at">fill =</span> genero, </span>
<span id="cb29-11"><a href="#cb29-11" aria-hidden="true" tabindex="-1"></a>      <span class="at">x =</span> <span class="fu">as.factor</span>(cor_raca), </span>
<span id="cb29-12"><a href="#cb29-12" aria-hidden="true" tabindex="-1"></a>      <span class="at">y =</span> perc_rec_ano_cargo_genero_cor_especie)) <span class="sc">+</span></span>
<span id="cb29-13"><a href="#cb29-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb29-14"><a href="#cb29-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb29-15"><a href="#cb29-15" aria-hidden="true" tabindex="-1"></a>   <span class="fu">aes</span>(<span class="at">label =</span> scales<span class="sc">::</span><span class="fu">percent</span>(perc_rec_ano_cargo_genero_cor_especie, <span class="at">accuracy =</span> <span class="fl">0.1</span>)),</span>
<span id="cb29-16"><a href="#cb29-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">position_dodge</span>(<span class="at">width =</span> <span class="fl">0.9</span>),</span>
<span id="cb29-17"><a href="#cb29-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust =</span> <span class="sc">-</span><span class="fl">0.5</span>,</span>
<span id="cb29-18"><a href="#cb29-18" aria-hidden="true" tabindex="-1"></a>    <span class="at">size =</span> <span class="dv">4</span></span>
<span id="cb29-19"><a href="#cb29-19" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">+</span></span>
<span id="cb29-20"><a href="#cb29-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">facet_wrap</span>(<span class="sc">~</span>ano_eleicao) <span class="sc">+</span></span>
<span id="cb29-21"><a href="#cb29-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb29-22"><a href="#cb29-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_fill_brewer</span>(<span class="at">palette =</span> <span class="st">"Set1"</span>) <span class="sc">+</span></span>
<span id="cb29-23"><a href="#cb29-23" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb29-24"><a href="#cb29-24" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span>percent,</span>
<span id="cb29-25"><a href="#cb29-25" aria-hidden="true" tabindex="-1"></a> <span class="co">#   limits = limites,</span></span>
<span id="cb29-26"><a href="#cb29-26" aria-hidden="true" tabindex="-1"></a><span class="co">#    breaks = quebras) +</span></span>
<span id="cb29-27"><a href="#cb29-27" aria-hidden="true" tabindex="-1"></a>  <span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="fl">0.20</span>), <span class="co">#0% a 22%</span></span>
<span id="cb29-28"><a href="#cb29-28" aria-hidden="true" tabindex="-1"></a>    <span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="fl">0.20</span>, <span class="at">by =</span> <span class="fl">0.02</span>)) <span class="sc">+</span></span>
<span id="cb29-29"><a href="#cb29-29" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb29-30"><a href="#cb29-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Race/color"</span>, </span>
<span id="cb29-31"><a href="#cb29-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Proportion of cash-equivalent funding (%)"</span>) <span class="sc">+</span></span>
<span id="cb29-32"><a href="#cb29-32" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb29-33"><a href="#cb29-33" aria-hidden="true" tabindex="-1"></a>    <span class="co">#panel.background = element_rect(fill='transparent'),</span></span>
<span id="cb29-34"><a href="#cb29-34" aria-hidden="true" tabindex="-1"></a>    <span class="co">#plot.background = element_rect(fill='transparent', color=NA),</span></span>
<span id="cb29-35"><a href="#cb29-35" aria-hidden="true" tabindex="-1"></a>    <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb29-36"><a href="#cb29-36" aria-hidden="true" tabindex="-1"></a>    <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb29-37"><a href="#cb29-37" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">14</span>), <span class="co">#RAÇAS</span></span>
<span id="cb29-38"><a href="#cb29-38" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">14</span>), <span class="co"># % 0 A 100%</span></span>
<span id="cb29-39"><a href="#cb29-39" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>), <span class="co"># legenda horizontal</span></span>
<span id="cb29-40"><a href="#cb29-40" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>), <span class="co"># legenda vertical</span></span>
<span id="cb29-41"><a href="#cb29-41" aria-hidden="true" tabindex="-1"></a>    <span class="at">strip.text =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>),    </span>
<span id="cb29-42"><a href="#cb29-42" aria-hidden="true" tabindex="-1"></a>    <span class="at">legend.title =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb29-43"><a href="#cb29-43" aria-hidden="true" tabindex="-1"></a>    <span class="at">legend.text =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>))</span>
<span id="cb29-44"><a href="#cb29-44" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb29-45"><a href="#cb29-45" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb29-46"><a href="#cb29-46" aria-hidden="true" tabindex="-1"></a>g2_figure</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">
<div id="fig-2" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<p><img src="artigo-rbcp-2025_EN_files/figure-html/fig-2-1.png" class="img-fluid figure-img" alt="Proportion of cash-equivalent funding of candidates to state deputy, in 2018 and 2022, by gender and race" width="768"></p>
<figcaption class="figure-caption">Figure&nbsp;2: Proportion of cash-equivalent funding of candidates to state deputy, in 2018 and 2022, by gender and race</figcaption>
</figure>
</div>
</div>
</div>
<p>Save figure</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="fu">grava_figura</span>(<span class="st">"..//Figuras//paper-fig-2"</span>, <span class="st">"png"</span>)</span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a>g2_figure</span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a><span class="fu">dev.off</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>png 
  2 </code></pre>
</div>
</div>
</section>
</section>
<section id="when-the-funds-were-transferred" class="level2">
<h2 class="anchored" data-anchor-id="when-the-funds-were-transferred">When the funds were transferred</h2>
<section id="graph-3---ratio-between-the-group-and-the-overall-average-of-public-funding-of-candidates-for-federal-deputy-by-gender-and-race-each-week" class="level3">
<h3 class="anchored" data-anchor-id="graph-3---ratio-between-the-group-and-the-overall-average-of-public-funding-of-candidates-for-federal-deputy-by-gender-and-race-each-week">Graph 3 - Ratio between the group and the overall average of public funding of candidates for federal deputy by gender and race, each week</h3>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>The amount of public revenue for the week received by the group (gender, race) weighted by the number of applications is equivalent to the average public revenue for that week.</p>
</div>
</div>
<p>Create data object</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Federal Deputy</span></span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a>g3_data <span class="ot">&lt;-</span>  receitas_publicas_semana_dep_fed <span class="sc">%&gt;%</span> </span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter_at</span>(<span class="fu">vars</span>(<span class="fu">everything</span>()), <span class="fu">all_vars</span>(<span class="sc">!</span><span class="fu">is.na</span>(.))) <span class="sc">%&gt;%</span></span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true" tabindex="-1"></a>    genero <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"Men"</span>, <span class="st">"Women"</span>),</span>
<span id="cb32-6"><a href="#cb32-6" aria-hidden="true" tabindex="-1"></a>    cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'White'</span>, <span class="st">'Black'</span>))</span>
<span id="cb32-7"><a href="#cb32-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb32-8"><a href="#cb32-8" aria-hidden="true" tabindex="-1"></a><span class="co"># para alterar a ordem das barras, para ficar como na versão em português</span></span>
<span id="cb32-9"><a href="#cb32-9" aria-hidden="true" tabindex="-1"></a>g3_data <span class="ot">&lt;-</span> g3_data <span class="sc">%&gt;%</span></span>
<span id="cb32-10"><a href="#cb32-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb32-11"><a href="#cb32-11" aria-hidden="true" tabindex="-1"></a>    <span class="at">genero_cor =</span> <span class="fu">factor</span>(</span>
<span id="cb32-12"><a href="#cb32-12" aria-hidden="true" tabindex="-1"></a>      <span class="fu">paste</span>(genero, cor_raca, <span class="at">sep =</span> <span class="st">"."</span>),</span>
<span id="cb32-13"><a href="#cb32-13" aria-hidden="true" tabindex="-1"></a>      <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"Men.White"</span>, <span class="st">"Men.Black"</span>, <span class="st">"Women.White"</span>, <span class="st">"Women.Black"</span>)</span>
<span id="cb32-14"><a href="#cb32-14" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb32-15"><a href="#cb32-15" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb32-16"><a href="#cb32-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb32-17"><a href="#cb32-17" aria-hidden="true" tabindex="-1"></a>max_media_receita_a <span class="ot">&lt;-</span> <span class="fu">max</span>(g3_data<span class="sc">$</span>media_receitas_genero_cor)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>Plot figure (Federal Deputy)</p>
<div class="cell output">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Definir idioma para visualizar data em inglês </span></span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a><span class="fu">invisible</span>(<span class="fu">Sys.setlocale</span>(<span class="st">"LC_TIME"</span>, <span class="st">"English"</span>))</span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-4"><a href="#cb33-4" aria-hidden="true" tabindex="-1"></a>limites <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">0</span>, max_media_receita_a) <span class="sc">*</span> <span class="fl">1.1</span></span>
<span id="cb33-5"><a href="#cb33-5" aria-hidden="true" tabindex="-1"></a>quebras <span class="ot">&lt;-</span> <span class="fu">seq</span>(limites[<span class="dv">1</span>], limites[<span class="dv">2</span>], <span class="at">by =</span> <span class="dv">20000</span>)</span>
<span id="cb33-6"><a href="#cb33-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-7"><a href="#cb33-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-8"><a href="#cb33-8" aria-hidden="true" tabindex="-1"></a><span class="co"># 2018</span></span>
<span id="cb33-9"><a href="#cb33-9" aria-hidden="true" tabindex="-1"></a>g3_2018_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb33-10"><a href="#cb33-10" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g3_data <span class="sc">%&gt;%</span> </span>
<span id="cb33-11"><a href="#cb33-11" aria-hidden="true" tabindex="-1"></a>    <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2018</span>),</span>
<span id="cb33-12"><a href="#cb33-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(</span>
<span id="cb33-13"><a href="#cb33-13" aria-hidden="true" tabindex="-1"></a><span class="co">#    fill = interaction(genero, cor_raca, lex.order = TRUE),</span></span>
<span id="cb33-14"><a href="#cb33-14" aria-hidden="true" tabindex="-1"></a>     <span class="at">fill =</span> genero_cor,</span>
<span id="cb33-15"><a href="#cb33-15" aria-hidden="true" tabindex="-1"></a>     <span class="at">x =</span> semana_receita, </span>
<span id="cb33-16"><a href="#cb33-16" aria-hidden="true" tabindex="-1"></a>      <span class="at">y =</span> media_receitas_genero_cor)) <span class="sc">+</span></span>
<span id="cb33-17"><a href="#cb33-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb33-18"><a href="#cb33-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb33-19"><a href="#cb33-19" aria-hidden="true" tabindex="-1"></a>    <span class="fu">aes</span>(<span class="at">label =</span> <span class="fu">paste0</span>(</span>
<span id="cb33-20"><a href="#cb33-20" aria-hidden="true" tabindex="-1"></a>      <span class="st">"("</span>,</span>
<span id="cb33-21"><a href="#cb33-21" aria-hidden="true" tabindex="-1"></a>      <span class="fu">sprintf</span>(<span class="st">"%0.1f"</span>, <span class="fu">round</span>(media_receitas_genero_cor <span class="sc">/</span> media_receitas_semana, <span class="dv">1</span>)),</span>
<span id="cb33-22"><a href="#cb33-22" aria-hidden="true" tabindex="-1"></a>      <span class="st">")"</span></span>
<span id="cb33-23"><a href="#cb33-23" aria-hidden="true" tabindex="-1"></a>  <span class="co">#   , sep = "")</span></span>
<span id="cb33-24"><a href="#cb33-24" aria-hidden="true" tabindex="-1"></a>    )),</span>
<span id="cb33-25"><a href="#cb33-25" aria-hidden="true" tabindex="-1"></a>    <span class="at">stat =</span> <span class="st">"identity"</span>,</span>
<span id="cb33-26"><a href="#cb33-26" aria-hidden="true" tabindex="-1"></a>    <span class="at">size =</span> <span class="dv">3</span>,</span>
<span id="cb33-27"><a href="#cb33-27" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">position_dodge</span>(<span class="dv">6</span>),</span>
<span id="cb33-28"><a href="#cb33-28" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust =</span> <span class="sc">-</span><span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb33-29"><a href="#cb33-29" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_x_date</span>(</span>
<span id="cb33-30"><a href="#cb33-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> <span class="fu">as.Date</span>(min_data_campanha_2018),</span>
<span id="cb33-31"><a href="#cb33-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">date_format</span>(<span class="st">"%b-%d"</span>), </span>
<span id="cb33-32"><a href="#cb33-32" aria-hidden="true" tabindex="-1"></a>    <span class="at">breaks =</span> <span class="st">"1 week"</span>) <span class="sc">+</span></span>
<span id="cb33-33"><a href="#cb33-33" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb33-34"><a href="#cb33-34" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_number</span>(<span class="at">scale_cut =</span> scales<span class="sc">::</span><span class="fu">cut_short_scale</span>()),</span>
<span id="cb33-35"><a href="#cb33-35" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> limites, <span class="at">breaks =</span> quebras) <span class="sc">+</span></span>
<span id="cb33-36"><a href="#cb33-36" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb33-37"><a href="#cb33-37" aria-hidden="true" tabindex="-1"></a>    <span class="at">title =</span> <span class="st">"2018"</span>,</span>
<span id="cb33-38"><a href="#cb33-38" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Month - First day of the week"</span>,</span>
<span id="cb33-39"><a href="#cb33-39" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Average funding by group (BRL)"</span>,</span>
<span id="cb33-40"><a href="#cb33-40" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> <span class="st">"Gender.Race"</span>) <span class="sc">+</span></span>
<span id="cb33-41"><a href="#cb33-41" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(<span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"transparent"</span>),</span>
<span id="cb33-42"><a href="#cb33-42" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb33-43"><a href="#cb33-43" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.y =</span> <span class="fu">element_line</span>(<span class="at">linewidth =</span> <span class="fl">0.1</span>, </span>
<span id="cb33-44"><a href="#cb33-44" aria-hidden="true" tabindex="-1"></a>                                          <span class="at">colour =</span> <span class="st">"grey50"</span>),</span>
<span id="cb33-45"><a href="#cb33-45" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb33-46"><a href="#cb33-46" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb33-47"><a href="#cb33-47" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb33-48"><a href="#cb33-48" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>),</span>
<span id="cb33-49"><a href="#cb33-49" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>),</span>
<span id="cb33-50"><a href="#cb33-50" aria-hidden="true" tabindex="-1"></a>        <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>, <span class="at">face =</span> <span class="st">"bold"</span>),</span>
<span id="cb33-51"><a href="#cb33-51" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb33-52"><a href="#cb33-52" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.position =</span> <span class="st">"bottom"</span>)</span>
<span id="cb33-53"><a href="#cb33-53" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-54"><a href="#cb33-54" aria-hidden="true" tabindex="-1"></a><span class="co"># 2022</span></span>
<span id="cb33-55"><a href="#cb33-55" aria-hidden="true" tabindex="-1"></a>g3_2022_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb33-56"><a href="#cb33-56" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g3_data <span class="sc">%&gt;%</span> </span>
<span id="cb33-57"><a href="#cb33-57" aria-hidden="true" tabindex="-1"></a>    <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2022</span>),</span>
<span id="cb33-58"><a href="#cb33-58" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(</span>
<span id="cb33-59"><a href="#cb33-59" aria-hidden="true" tabindex="-1"></a>  <span class="co">#  fill = interaction(genero, cor_raca, lex.order = TRUE),</span></span>
<span id="cb33-60"><a href="#cb33-60" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> genero_cor, </span>
<span id="cb33-61"><a href="#cb33-61" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> semana_receita, </span>
<span id="cb33-62"><a href="#cb33-62" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> media_receitas_genero_cor)) <span class="sc">+</span></span>
<span id="cb33-63"><a href="#cb33-63" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb33-64"><a href="#cb33-64" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb33-65"><a href="#cb33-65" aria-hidden="true" tabindex="-1"></a>    <span class="fu">aes</span>(<span class="at">label =</span> <span class="fu">paste</span>(</span>
<span id="cb33-66"><a href="#cb33-66" aria-hidden="true" tabindex="-1"></a>      <span class="st">"("</span>,</span>
<span id="cb33-67"><a href="#cb33-67" aria-hidden="true" tabindex="-1"></a>      <span class="fu">sprintf</span>(<span class="st">"%0.1f"</span>, </span>
<span id="cb33-68"><a href="#cb33-68" aria-hidden="true" tabindex="-1"></a>              <span class="fu">round</span>(media_receitas_genero_cor <span class="sc">/</span> media_receitas_semana, <span class="dv">1</span>)), <span class="st">")"</span>,</span>
<span id="cb33-69"><a href="#cb33-69" aria-hidden="true" tabindex="-1"></a>      <span class="at">sep =</span> <span class="st">""</span>)),</span>
<span id="cb33-70"><a href="#cb33-70" aria-hidden="true" tabindex="-1"></a>    <span class="at">stat =</span> <span class="st">"identity"</span>,</span>
<span id="cb33-71"><a href="#cb33-71" aria-hidden="true" tabindex="-1"></a>    <span class="at">size =</span> <span class="dv">3</span>,</span>
<span id="cb33-72"><a href="#cb33-72" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">position_dodge</span>(<span class="dv">6</span>),</span>
<span id="cb33-73"><a href="#cb33-73" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust =</span> <span class="sc">-</span><span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb33-74"><a href="#cb33-74" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_x_date</span>(</span>
<span id="cb33-75"><a href="#cb33-75" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> <span class="fu">as.Date</span>(min_data_campanha_2022),</span>
<span id="cb33-76"><a href="#cb33-76" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">date_format</span>(<span class="st">"%b-%d"</span>), </span>
<span id="cb33-77"><a href="#cb33-77" aria-hidden="true" tabindex="-1"></a>    <span class="at">breaks =</span> <span class="st">"1 week"</span>) <span class="sc">+</span></span>
<span id="cb33-78"><a href="#cb33-78" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb33-79"><a href="#cb33-79" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_number</span>(<span class="at">scale_cut =</span> scales<span class="sc">::</span><span class="fu">cut_short_scale</span>()),</span>
<span id="cb33-80"><a href="#cb33-80" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> limites, <span class="at">breaks =</span> quebras) <span class="sc">+</span></span>
<span id="cb33-81"><a href="#cb33-81" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb33-82"><a href="#cb33-82" aria-hidden="true" tabindex="-1"></a>    <span class="at">title =</span> <span class="st">"2022"</span>,</span>
<span id="cb33-83"><a href="#cb33-83" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Month - First day of the week"</span>,</span>
<span id="cb33-84"><a href="#cb33-84" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Average funding by group (BRL)"</span>,</span>
<span id="cb33-85"><a href="#cb33-85" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> <span class="st">"Gender.Race"</span>) <span class="sc">+</span></span>
<span id="cb33-86"><a href="#cb33-86" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(<span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"transparent"</span>),</span>
<span id="cb33-87"><a href="#cb33-87" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb33-88"><a href="#cb33-88" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.y =</span> <span class="fu">element_line</span>(<span class="at">linewidth =</span> <span class="fl">0.1</span>, </span>
<span id="cb33-89"><a href="#cb33-89" aria-hidden="true" tabindex="-1"></a>                                          <span class="at">colour =</span> <span class="st">"grey50"</span>),</span>
<span id="cb33-90"><a href="#cb33-90" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb33-91"><a href="#cb33-91" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb33-92"><a href="#cb33-92" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb33-93"><a href="#cb33-93" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>),</span>
<span id="cb33-94"><a href="#cb33-94" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>),</span>
<span id="cb33-95"><a href="#cb33-95" aria-hidden="true" tabindex="-1"></a>        <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>, <span class="at">face =</span> <span class="st">"bold"</span>),</span>
<span id="cb33-96"><a href="#cb33-96" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb33-97"><a href="#cb33-97" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.position =</span> <span class="st">"bottom"</span>) <span class="sc">+</span></span>
<span id="cb33-98"><a href="#cb33-98" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_vline</span>(</span>
<span id="cb33-99"><a href="#cb33-99" aria-hidden="true" tabindex="-1"></a>    <span class="at">xintercept =</span> <span class="fu">as.Date</span>(<span class="st">"2022-09-13"</span>),</span>
<span id="cb33-100"><a href="#cb33-100" aria-hidden="true" tabindex="-1"></a>    <span class="at">lwd =</span> <span class="dv">1</span>,</span>
<span id="cb33-101"><a href="#cb33-101" aria-hidden="true" tabindex="-1"></a>    <span class="at">linetype =</span> <span class="dv">3</span>,</span>
<span id="cb33-102"><a href="#cb33-102" aria-hidden="true" tabindex="-1"></a>    <span class="at">colour=</span><span class="st">"black"</span>) <span class="sc">+</span></span>
<span id="cb33-103"><a href="#cb33-103" aria-hidden="true" tabindex="-1"></a>  <span class="fu">annotate</span>(<span class="st">"text"</span>, <span class="at">x=</span><span class="fu">as.Date</span>(<span class="st">"2022-09-12"</span>), <span class="at">y=</span><span class="dv">700000000</span>, </span>
<span id="cb33-104"><a href="#cb33-104" aria-hidden="true" tabindex="-1"></a>           <span class="at">label=</span><span class="st">"1st. partial"</span>, <span class="at">angle=</span><span class="dv">90</span>) </span>
<span id="cb33-105"><a href="#cb33-105" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-106"><a href="#cb33-106" aria-hidden="true" tabindex="-1"></a>g3_figure <span class="ot">&lt;-</span> g3_2018_figure <span class="sc">+</span> g3_2022_figure <span class="sc">+</span> <span class="fu">plot_layout</span>(<span class="at">ncol =</span> <span class="dv">1</span>, </span>
<span id="cb33-107"><a href="#cb33-107" aria-hidden="true" tabindex="-1"></a>                                                           <span class="at">nrow =</span> <span class="dv">2</span>)</span>
<span id="cb33-108"><a href="#cb33-108" aria-hidden="true" tabindex="-1"></a>g3_figure</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">
<div id="fig-3" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<p><img src="artigo-rbcp-2025_EN_files/figure-html/fig-3-1.png" class="img-fluid figure-img" alt="Ratio between the group average and the overall average of public funding of candidates for federal deputy by gender and color/race, each week" width="960"></p>
<figcaption class="figure-caption">Figure&nbsp;3: Ratio between the group average and the overall average of public funding of candidates for federal deputy by gender and color/race, each week</figcaption>
</figure>
</div>
</div>
</div>
<p>Save figure (Federal Deputy)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a><span class="fu">grava_figura</span>(<span class="st">"..//Figuras//paper-fig-3"</span>, <span class="st">"png"</span>)</span>
<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a>g3_figure</span>
<span id="cb34-3"><a href="#cb34-3" aria-hidden="true" tabindex="-1"></a><span class="fu">dev.off</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>png 
  2 </code></pre>
</div>
</div>
</section>
<section id="graph-4---ratio-between-the-group-and-the-overall-average-of-public-funding-of-candidates-for-state-deputy-by-gender-and-colorrace-each-week" class="level3">
<h3 class="anchored" data-anchor-id="graph-4---ratio-between-the-group-and-the-overall-average-of-public-funding-of-candidates-for-state-deputy-by-gender-and-colorrace-each-week">Graph 4 - Ratio between the group and the overall average of public funding of candidates for state deputy by gender and color/race, each week</h3>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>The amount of public revenue for the week received by the group (gender, race) weighted by the number of applications is equivalent to the average public revenue for that week.</p>
</div>
</div>
<p>Create data object</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a><span class="co"># State Deputy</span></span>
<span id="cb36-2"><a href="#cb36-2" aria-hidden="true" tabindex="-1"></a>g4_data <span class="ot">&lt;-</span>  receitas_publicas_semana_dep_est <span class="sc">%&gt;%</span> </span>
<span id="cb36-3"><a href="#cb36-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter_at</span>(<span class="fu">vars</span>(<span class="fu">everything</span>()), <span class="fu">all_vars</span>(<span class="sc">!</span><span class="fu">is.na</span>(.))) <span class="sc">%&gt;%</span></span>
<span id="cb36-4"><a href="#cb36-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb36-5"><a href="#cb36-5" aria-hidden="true" tabindex="-1"></a>    genero <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"Men"</span>, <span class="st">"Women"</span>),</span>
<span id="cb36-6"><a href="#cb36-6" aria-hidden="true" tabindex="-1"></a>    cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'White'</span>, <span class="st">'Black'</span>))</span>
<span id="cb36-7"><a href="#cb36-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-8"><a href="#cb36-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-9"><a href="#cb36-9" aria-hidden="true" tabindex="-1"></a><span class="co"># para alterar a ordem das barras, para ficar como na versão em português</span></span>
<span id="cb36-10"><a href="#cb36-10" aria-hidden="true" tabindex="-1"></a>g4_data <span class="ot">&lt;-</span> g4_data <span class="sc">%&gt;%</span></span>
<span id="cb36-11"><a href="#cb36-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb36-12"><a href="#cb36-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">genero_cor =</span> <span class="fu">factor</span>(</span>
<span id="cb36-13"><a href="#cb36-13" aria-hidden="true" tabindex="-1"></a>      <span class="fu">paste</span>(genero, cor_raca, <span class="at">sep =</span> <span class="st">"."</span>),</span>
<span id="cb36-14"><a href="#cb36-14" aria-hidden="true" tabindex="-1"></a>      <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"Men.White"</span>, <span class="st">"Men.Black"</span>, <span class="st">"Women.White"</span>, <span class="st">"Women.Black"</span>)</span>
<span id="cb36-15"><a href="#cb36-15" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb36-16"><a href="#cb36-16" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb36-17"><a href="#cb36-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-18"><a href="#cb36-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-19"><a href="#cb36-19" aria-hidden="true" tabindex="-1"></a>max_media_receita_b <span class="ot">&lt;-</span> <span class="fu">max</span>(g4_data<span class="sc">$</span>media_receitas_genero_cor)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<p>Plot figure (State Deputy)</p>
<div class="cell output">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Definir idioma para visualizar data em inglês </span></span>
<span id="cb37-2"><a href="#cb37-2" aria-hidden="true" tabindex="-1"></a><span class="fu">invisible</span>(<span class="fu">Sys.setlocale</span>(<span class="st">"LC_TIME"</span>, <span class="st">"English"</span>))</span>
<span id="cb37-3"><a href="#cb37-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-4"><a href="#cb37-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-5"><a href="#cb37-5" aria-hidden="true" tabindex="-1"></a>limites <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">0</span>, max_media_receita_b) <span class="sc">*</span> <span class="fl">1.1</span></span>
<span id="cb37-6"><a href="#cb37-6" aria-hidden="true" tabindex="-1"></a>quebras <span class="ot">&lt;-</span> <span class="fu">seq</span>(limites[<span class="dv">1</span>], limites[<span class="dv">2</span>], <span class="at">by =</span> <span class="dv">20000</span>)</span>
<span id="cb37-7"><a href="#cb37-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-8"><a href="#cb37-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-9"><a href="#cb37-9" aria-hidden="true" tabindex="-1"></a><span class="co"># 2018</span></span>
<span id="cb37-10"><a href="#cb37-10" aria-hidden="true" tabindex="-1"></a>g4_2018_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb37-11"><a href="#cb37-11" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g4_data <span class="sc">%&gt;%</span> <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2018</span>),</span>
<span id="cb37-12"><a href="#cb37-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(</span>
<span id="cb37-13"><a href="#cb37-13" aria-hidden="true" tabindex="-1"></a>    <span class="co">#fill = interaction(genero, cor_raca, lex.order = TRUE),</span></span>
<span id="cb37-14"><a href="#cb37-14" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill=</span> genero_cor,</span>
<span id="cb37-15"><a href="#cb37-15" aria-hidden="true" tabindex="-1"></a>      <span class="at">x =</span> semana_receita, </span>
<span id="cb37-16"><a href="#cb37-16" aria-hidden="true" tabindex="-1"></a>      <span class="at">y =</span> media_receitas_genero_cor)) <span class="sc">+</span></span>
<span id="cb37-17"><a href="#cb37-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb37-18"><a href="#cb37-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb37-19"><a href="#cb37-19" aria-hidden="true" tabindex="-1"></a>    <span class="fu">aes</span>(<span class="at">label =</span> <span class="fu">paste0</span>(</span>
<span id="cb37-20"><a href="#cb37-20" aria-hidden="true" tabindex="-1"></a>      <span class="st">"("</span>,</span>
<span id="cb37-21"><a href="#cb37-21" aria-hidden="true" tabindex="-1"></a>      <span class="fu">sprintf</span>(<span class="st">"%0.1f"</span>, </span>
<span id="cb37-22"><a href="#cb37-22" aria-hidden="true" tabindex="-1"></a>              <span class="fu">round</span>(media_receitas_genero_cor <span class="sc">/</span> media_receitas_semana, <span class="dv">1</span>)),</span>
<span id="cb37-23"><a href="#cb37-23" aria-hidden="true" tabindex="-1"></a>      <span class="st">")"</span></span>
<span id="cb37-24"><a href="#cb37-24" aria-hidden="true" tabindex="-1"></a>    <span class="co"># , sep = "")),</span></span>
<span id="cb37-25"><a href="#cb37-25" aria-hidden="true" tabindex="-1"></a>    )),</span>
<span id="cb37-26"><a href="#cb37-26" aria-hidden="true" tabindex="-1"></a>    <span class="at">stat =</span> <span class="st">"identity"</span>,</span>
<span id="cb37-27"><a href="#cb37-27" aria-hidden="true" tabindex="-1"></a>    <span class="at">size =</span> <span class="dv">3</span>,</span>
<span id="cb37-28"><a href="#cb37-28" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">position_dodge</span>(<span class="dv">6</span>),</span>
<span id="cb37-29"><a href="#cb37-29" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust =</span> <span class="sc">-</span><span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb37-30"><a href="#cb37-30" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_x_date</span>(</span>
<span id="cb37-31"><a href="#cb37-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> <span class="fu">as.Date</span>(min_data_campanha_2018),</span>
<span id="cb37-32"><a href="#cb37-32" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">date_format</span>(<span class="st">"%b-%d"</span>), </span>
<span id="cb37-33"><a href="#cb37-33" aria-hidden="true" tabindex="-1"></a>    <span class="at">breaks =</span> <span class="st">"1 week"</span>) <span class="sc">+</span></span>
<span id="cb37-34"><a href="#cb37-34" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb37-35"><a href="#cb37-35" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_number</span>(<span class="at">scale_cut =</span> scales<span class="sc">::</span><span class="fu">cut_short_scale</span>()),</span>
<span id="cb37-36"><a href="#cb37-36" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> limites, <span class="at">breaks =</span> quebras) <span class="sc">+</span></span>
<span id="cb37-37"><a href="#cb37-37" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb37-38"><a href="#cb37-38" aria-hidden="true" tabindex="-1"></a>    <span class="at">title =</span> <span class="st">"2018"</span>,</span>
<span id="cb37-39"><a href="#cb37-39" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Month - First day of the week"</span>,</span>
<span id="cb37-40"><a href="#cb37-40" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Average funding by group (BRL)"</span>,</span>
<span id="cb37-41"><a href="#cb37-41" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> <span class="st">"Gender.Race"</span>) <span class="sc">+</span></span>
<span id="cb37-42"><a href="#cb37-42" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(<span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"transparent"</span>),</span>
<span id="cb37-43"><a href="#cb37-43" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb37-44"><a href="#cb37-44" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.y =</span> <span class="fu">element_line</span>(<span class="at">linewidth =</span> <span class="fl">0.1</span>, </span>
<span id="cb37-45"><a href="#cb37-45" aria-hidden="true" tabindex="-1"></a>                                          <span class="at">colour =</span> <span class="st">"grey50"</span>),</span>
<span id="cb37-46"><a href="#cb37-46" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb37-47"><a href="#cb37-47" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb37-48"><a href="#cb37-48" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb37-49"><a href="#cb37-49" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>),</span>
<span id="cb37-50"><a href="#cb37-50" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>),</span>
<span id="cb37-51"><a href="#cb37-51" aria-hidden="true" tabindex="-1"></a>        <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>, <span class="at">face =</span> <span class="st">"bold"</span>),</span>
<span id="cb37-52"><a href="#cb37-52" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb37-53"><a href="#cb37-53" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.position =</span> <span class="st">"bottom"</span>)</span>
<span id="cb37-54"><a href="#cb37-54" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-55"><a href="#cb37-55" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-56"><a href="#cb37-56" aria-hidden="true" tabindex="-1"></a><span class="co"># 2022</span></span>
<span id="cb37-57"><a href="#cb37-57" aria-hidden="true" tabindex="-1"></a>g4_2022_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb37-58"><a href="#cb37-58" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g4_data <span class="sc">%&gt;%</span> <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2022</span>),</span>
<span id="cb37-59"><a href="#cb37-59" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(</span>
<span id="cb37-60"><a href="#cb37-60" aria-hidden="true" tabindex="-1"></a>  <span class="co">#  fill = interaction(genero, cor_raca, lex.order = TRUE),</span></span>
<span id="cb37-61"><a href="#cb37-61" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> genero_cor,</span>
<span id="cb37-62"><a href="#cb37-62" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> semana_receita, </span>
<span id="cb37-63"><a href="#cb37-63" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> media_receitas_genero_cor)) <span class="sc">+</span></span>
<span id="cb37-64"><a href="#cb37-64" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb37-65"><a href="#cb37-65" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb37-66"><a href="#cb37-66" aria-hidden="true" tabindex="-1"></a>    <span class="fu">aes</span>(<span class="at">label =</span> <span class="fu">paste</span>(</span>
<span id="cb37-67"><a href="#cb37-67" aria-hidden="true" tabindex="-1"></a>      <span class="st">"("</span>,</span>
<span id="cb37-68"><a href="#cb37-68" aria-hidden="true" tabindex="-1"></a>      <span class="fu">sprintf</span>(<span class="st">"%0.1f"</span>, </span>
<span id="cb37-69"><a href="#cb37-69" aria-hidden="true" tabindex="-1"></a>              <span class="fu">round</span>(media_receitas_genero_cor <span class="sc">/</span> media_receitas_semana, <span class="dv">1</span>)),</span>
<span id="cb37-70"><a href="#cb37-70" aria-hidden="true" tabindex="-1"></a>      <span class="st">")"</span>,</span>
<span id="cb37-71"><a href="#cb37-71" aria-hidden="true" tabindex="-1"></a>      <span class="at">sep =</span> <span class="st">""</span>)),</span>
<span id="cb37-72"><a href="#cb37-72" aria-hidden="true" tabindex="-1"></a>    <span class="at">stat =</span> <span class="st">"identity"</span>,</span>
<span id="cb37-73"><a href="#cb37-73" aria-hidden="true" tabindex="-1"></a>    <span class="at">size =</span> <span class="dv">3</span>,</span>
<span id="cb37-74"><a href="#cb37-74" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">position_dodge</span>(<span class="dv">6</span>),</span>
<span id="cb37-75"><a href="#cb37-75" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust =</span> <span class="sc">-</span><span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb37-76"><a href="#cb37-76" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_x_date</span>(</span>
<span id="cb37-77"><a href="#cb37-77" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> <span class="fu">as.Date</span>(min_data_campanha_2022),</span>
<span id="cb37-78"><a href="#cb37-78" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">date_format</span>(<span class="st">"%b-%d"</span>), </span>
<span id="cb37-79"><a href="#cb37-79" aria-hidden="true" tabindex="-1"></a>    <span class="at">breaks =</span> <span class="st">"1 week"</span>) <span class="sc">+</span></span>
<span id="cb37-80"><a href="#cb37-80" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb37-81"><a href="#cb37-81" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_number</span>(<span class="at">scale_cut =</span> scales<span class="sc">::</span><span class="fu">cut_short_scale</span>()),</span>
<span id="cb37-82"><a href="#cb37-82" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> limites, <span class="at">breaks =</span> quebras) <span class="sc">+</span></span>
<span id="cb37-83"><a href="#cb37-83" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb37-84"><a href="#cb37-84" aria-hidden="true" tabindex="-1"></a>    <span class="at">title =</span> <span class="st">"2022"</span>,</span>
<span id="cb37-85"><a href="#cb37-85" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Month - First day of the week"</span>,</span>
<span id="cb37-86"><a href="#cb37-86" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Average funding by group (BRL)"</span>,</span>
<span id="cb37-87"><a href="#cb37-87" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> <span class="st">"Gender.Race"</span>) <span class="sc">+</span></span>
<span id="cb37-88"><a href="#cb37-88" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(<span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"transparent"</span>),</span>
<span id="cb37-89"><a href="#cb37-89" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb37-90"><a href="#cb37-90" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.y =</span> <span class="fu">element_line</span>(<span class="at">linewidth =</span> <span class="fl">0.1</span>, </span>
<span id="cb37-91"><a href="#cb37-91" aria-hidden="true" tabindex="-1"></a>                                          <span class="at">colour =</span> <span class="st">"grey50"</span>),</span>
<span id="cb37-92"><a href="#cb37-92" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb37-93"><a href="#cb37-93" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb37-94"><a href="#cb37-94" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb37-95"><a href="#cb37-95" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>),</span>
<span id="cb37-96"><a href="#cb37-96" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>),</span>
<span id="cb37-97"><a href="#cb37-97" aria-hidden="true" tabindex="-1"></a>        <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>, <span class="at">face =</span> <span class="st">"bold"</span>),</span>
<span id="cb37-98"><a href="#cb37-98" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb37-99"><a href="#cb37-99" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.position =</span> <span class="st">"bottom"</span>) <span class="sc">+</span></span>
<span id="cb37-100"><a href="#cb37-100" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_vline</span>(</span>
<span id="cb37-101"><a href="#cb37-101" aria-hidden="true" tabindex="-1"></a>    <span class="at">xintercept =</span> <span class="fu">as.Date</span>(<span class="st">"2022-09-13"</span>),</span>
<span id="cb37-102"><a href="#cb37-102" aria-hidden="true" tabindex="-1"></a>    <span class="at">lwd =</span> <span class="dv">1</span>,</span>
<span id="cb37-103"><a href="#cb37-103" aria-hidden="true" tabindex="-1"></a>    <span class="at">linetype =</span> <span class="dv">3</span>,</span>
<span id="cb37-104"><a href="#cb37-104" aria-hidden="true" tabindex="-1"></a>    <span class="at">colour=</span><span class="st">"black"</span>) <span class="sc">+</span></span>
<span id="cb37-105"><a href="#cb37-105" aria-hidden="true" tabindex="-1"></a>  <span class="fu">annotate</span>(<span class="st">"text"</span>, <span class="at">x=</span><span class="fu">as.Date</span>(<span class="st">"2022-09-12"</span>), <span class="at">y=</span><span class="dv">700000000</span>, </span>
<span id="cb37-106"><a href="#cb37-106" aria-hidden="true" tabindex="-1"></a>           <span class="at">label=</span><span class="st">"1a. parcial"</span>, <span class="at">angle=</span><span class="dv">90</span>) </span>
<span id="cb37-107"><a href="#cb37-107" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-108"><a href="#cb37-108" aria-hidden="true" tabindex="-1"></a>g4_figure <span class="ot">&lt;-</span> g4_2018_figure <span class="sc">+</span> g4_2022_figure <span class="sc">+</span> <span class="fu">plot_layout</span>(<span class="at">ncol =</span> <span class="dv">1</span>, </span>
<span id="cb37-109"><a href="#cb37-109" aria-hidden="true" tabindex="-1"></a>                                                           <span class="at">nrow =</span> <span class="dv">2</span>)</span>
<span id="cb37-110"><a href="#cb37-110" aria-hidden="true" tabindex="-1"></a>g4_figure</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">
<div id="fig-4" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<p><img src="artigo-rbcp-2025_EN_files/figure-html/fig-4-1.png" class="img-fluid figure-img" alt="Ratio between the group average and the overall average of public funding of candidates for state deputy by gender and race, each week" width="960"></p>
<figcaption class="figure-caption">Figure&nbsp;4: Ratio between the group average and the overall average of public funding of candidates for state deputy by gender and race, each week</figcaption>
</figure>
</div>
</div>
</div>
<p>Save figure (State Deputy)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a><span class="co"># save figure in PNG format</span></span>
<span id="cb38-2"><a href="#cb38-2" aria-hidden="true" tabindex="-1"></a><span class="fu">grava_figura</span>(<span class="st">"..//Figuras//paper-fig-4"</span>, <span class="st">"png"</span>)</span>
<span id="cb38-3"><a href="#cb38-3" aria-hidden="true" tabindex="-1"></a>g4_figure</span>
<span id="cb38-4"><a href="#cb38-4" aria-hidden="true" tabindex="-1"></a><span class="fu">dev.off</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>png 
  2 </code></pre>
</div>
</div>
</section>
</section>
<section id="transfers-between-candidate-providers" class="level2">
<h2 class="anchored" data-anchor-id="transfers-between-candidate-providers">Transfers between candidate providers</h2>
<p>Define the format style of the tables</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a><span class="fu">set_flextable_defaults</span>(</span>
<span id="cb40-2"><a href="#cb40-2" aria-hidden="true" tabindex="-1"></a>  <span class="at">split =</span> <span class="cn">TRUE</span>,</span>
<span id="cb40-3"><a href="#cb40-3" aria-hidden="true" tabindex="-1"></a>  <span class="at">table_align =</span> <span class="st">"center"</span>,</span>
<span id="cb40-4"><a href="#cb40-4" aria-hidden="true" tabindex="-1"></a>  <span class="at">digits =</span> <span class="dv">2</span>, </span>
<span id="cb40-5"><a href="#cb40-5" aria-hidden="true" tabindex="-1"></a>  <span class="at">border.color =</span> <span class="st">"black"</span>)</span>
<span id="cb40-6"><a href="#cb40-6" aria-hidden="true" tabindex="-1"></a>properties1 <span class="ot">&lt;-</span> <span class="fu">fp_text</span>(<span class="at">font.family =</span> <span class="st">"Times New Roman"</span>,</span>
<span id="cb40-7"><a href="#cb40-7" aria-hidden="true" tabindex="-1"></a>                      <span class="at">font.size =</span> <span class="dv">10</span>)</span>
<span id="cb40-8"><a href="#cb40-8" aria-hidden="true" tabindex="-1"></a>properties2 <span class="ot">&lt;-</span> <span class="fu">fp_text</span>(<span class="at">font.family =</span> <span class="st">"Times New Roman"</span>,</span>
<span id="cb40-9"><a href="#cb40-9" aria-hidden="true" tabindex="-1"></a>                      <span class="at">font.size =</span> <span class="dv">10</span>,</span>
<span id="cb40-10"><a href="#cb40-10" aria-hidden="true" tabindex="-1"></a>                      <span class="at">bold =</span> <span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<section id="table-1---transfer-of-funds-between-candidates-by-gender" class="level3">
<h3 class="anchored" data-anchor-id="table-1---transfer-of-funds-between-candidates-by-gender">Table 1 - Transfer of funds between candidates, by gender</h3>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>Here, we consider only funding originating from public revenue.</p>
</div>
</div>
<p>Create dataset for table 1</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a>d_t_1 <span class="ot">&lt;-</span> receitas <span class="sc">%&gt;%</span></span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2022</span>,</span>
<span id="cb41-3"><a href="#cb41-3" aria-hidden="true" tabindex="-1"></a>         NR_CPF_CNPJ_DOADOR <span class="sc">!=</span> NR_CNPJ_PRESTADOR_CONTA,</span>
<span id="cb41-4"><a href="#cb41-4" aria-hidden="true" tabindex="-1"></a>         DS_FONTE_RECURSO <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'Recursos de outros candidatos'</span>, </span>
<span id="cb41-5"><a href="#cb41-5" aria-hidden="true" tabindex="-1"></a>                                 <span class="st">'Recursos de partido político'</span>),</span>
<span id="cb41-6"><a href="#cb41-6" aria-hidden="true" tabindex="-1"></a>         tipo_recurso <span class="sc">==</span> <span class="st">'Public'</span>,</span>
<span id="cb41-7"><a href="#cb41-7" aria-hidden="true" tabindex="-1"></a>         genero <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'Men'</span>, <span class="st">'Women'</span>),</span>
<span id="cb41-8"><a href="#cb41-8" aria-hidden="true" tabindex="-1"></a>         genero_doador <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'Men'</span>, <span class="st">'Women'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb41-9"><a href="#cb41-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb41-10"><a href="#cb41-10" aria-hidden="true" tabindex="-1"></a>         <span class="at">position =</span> DS_CARGO,</span>
<span id="cb41-11"><a href="#cb41-11" aria-hidden="true" tabindex="-1"></a>         <span class="at">gender_accountaunt =</span> genero,</span>
<span id="cb41-12"><a href="#cb41-12" aria-hidden="true" tabindex="-1"></a>         <span class="at">gender_donor =</span> genero_doador) <span class="sc">%&gt;%</span></span>
<span id="cb41-13"><a href="#cb41-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span><span class="fu">c</span>(ano_eleicao, DS_CARGO, genero, genero_doador)) <span class="sc">%&gt;%</span></span>
<span id="cb41-14"><a href="#cb41-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(gender_donor, gender_accountaunt) <span class="sc">%&gt;%</span></span>
<span id="cb41-15"><a href="#cb41-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">transfers_between_accountants =</span> <span class="fu">sum</span>(TOTAL_RECEITA),</span>
<span id="cb41-16"><a href="#cb41-16" aria-hidden="true" tabindex="-1"></a>            <span class="at">.groups =</span> <span class="st">'drop'</span>) <span class="sc">%&gt;%</span></span>
<span id="cb41-17"><a href="#cb41-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb41-18"><a href="#cb41-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(gender_donor) <span class="sc">%&gt;%</span></span>
<span id="cb41-19"><a href="#cb41-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb41-20"><a href="#cb41-20" aria-hidden="true" tabindex="-1"></a>    <span class="at">prc_transfers_rel_gender_donor =</span> transfers_between_accountants <span class="sc">/</span> </span>
<span id="cb41-21"><a href="#cb41-21" aria-hidden="true" tabindex="-1"></a>        <span class="fu">sum</span>(transfers_between_accountants)) <span class="sc">%&gt;%</span></span>
<span id="cb41-22"><a href="#cb41-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb41-23"><a href="#cb41-23" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb41-24"><a href="#cb41-24" aria-hidden="true" tabindex="-1"></a>      <span class="at">prc_transfers_rel_total =</span> transfers_between_accountants <span class="sc">/</span> </span>
<span id="cb41-25"><a href="#cb41-25" aria-hidden="true" tabindex="-1"></a>        <span class="fu">sum</span>(transfers_between_accountants)) <span class="sc">%&gt;%</span></span>
<span id="cb41-26"><a href="#cb41-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(gender_donor, gender_accountaunt, </span>
<span id="cb41-27"><a href="#cb41-27" aria-hidden="true" tabindex="-1"></a>         transfers_between_accountants,</span>
<span id="cb41-28"><a href="#cb41-28" aria-hidden="true" tabindex="-1"></a>         prc_transfers_rel_total,</span>
<span id="cb41-29"><a href="#cb41-29" aria-hidden="true" tabindex="-1"></a>         prc_transfers_rel_gender_donor) <span class="sc">%&gt;%</span></span>
<span id="cb41-30"><a href="#cb41-30" aria-hidden="true" tabindex="-1"></a>  <span class="fu">as_tibble</span>()</span>
<span id="cb41-31"><a href="#cb41-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-32"><a href="#cb41-32" aria-hidden="true" tabindex="-1"></a>d_t_1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":["gender_donor"],"name":[1],"type":["chr"],"align":["left"]},{"label":["gender_accountaunt"],"name":[2],"type":["chr"],"align":["left"]},{"label":["transfers_between_accountants"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["prc_transfers_rel_total"],"name":[4],"type":["dbl"],"align":["right"]},{"label":["prc_transfers_rel_gender_donor"],"name":[5],"type":["dbl"],"align":["right"]}],"data":[{"1":"Men","2":"Men","3":"109704048","4":"0.69474889","5":"0.8439305"},{"1":"Men","2":"Women","3":"20287762","4":"0.12848113","5":"0.1560695"},{"1":"Women","2":"Men","3":"10613091","4":"0.06721204","5":"0.3802231"},{"1":"Women","2":"Women","3":"17299704","4":"0.10955795","5":"0.6197769"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
<p>Plot table 1 (HTML format)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb42"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a>t_1 <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(d_t_1) <span class="sc">|&gt;</span></span>
<span id="cb42-2"><a href="#cb42-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">delete_part</span>(<span class="st">"foot"</span>) <span class="sc">|&gt;</span></span>
<span id="cb42-3"><a href="#cb42-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">delete_rows</span>(<span class="at">i =</span> <span class="dv">2</span>, <span class="at">part =</span> <span class="st">"header"</span>) <span class="sc">|&gt;</span></span>
<span id="cb42-4"><a href="#cb42-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mk_par</span>(</span>
<span id="cb42-5"><a href="#cb42-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">j =</span> <span class="dv">4</span>, <span class="at">part =</span> <span class="st">"body"</span>,</span>
<span id="cb42-6"><a href="#cb42-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">value =</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_transfers_rel_total,</span>
<span id="cb42-7"><a href="#cb42-7" aria-hidden="true" tabindex="-1"></a>                                  <span class="at">formatter =</span> fmt_pct))) <span class="sc">|&gt;</span></span>
<span id="cb42-8"><a href="#cb42-8" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mk_par</span>(</span>
<span id="cb42-9"><a href="#cb42-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">j =</span> <span class="dv">5</span>, <span class="at">part =</span> <span class="st">"body"</span>,</span>
<span id="cb42-10"><a href="#cb42-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">value =</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_transfers_rel_gender_donor,</span>
<span id="cb42-11"><a href="#cb42-11" aria-hidden="true" tabindex="-1"></a>                                  <span class="at">formatter =</span> fmt_pct))) <span class="sc">|&gt;</span></span>
<span id="cb42-12"><a href="#cb42-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb42-13"><a href="#cb42-13" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb42-14"><a href="#cb42-14" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb42-15"><a href="#cb42-15" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender_accountaunt"</span> <span class="ot">=</span> <span class="st">"Accountant gender"</span>,</span>
<span id="cb42-16"><a href="#cb42-16" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender_donor"</span> <span class="ot">=</span> <span class="st">"Donor gender"</span>,</span>
<span id="cb42-17"><a href="#cb42-17" aria-hidden="true" tabindex="-1"></a>      <span class="st">"transfers_between_accountants"</span> <span class="ot">=</span> <span class="st">"Transfer amount (BRL)"</span>,</span>
<span id="cb42-18"><a href="#cb42-18" aria-hidden="true" tabindex="-1"></a>      <span class="st">"prc_transfers_rel_total"</span> <span class="ot">=</span> <span class="st">"% (rel. total)"</span>,</span>
<span id="cb42-19"><a href="#cb42-19" aria-hidden="true" tabindex="-1"></a>      <span class="st">"prc_transfers_rel_gender_donor"</span> <span class="ot">=</span> <span class="st">"% (rel. donor gender)"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb42-20"><a href="#cb42-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb42-21"><a href="#cb42-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">1.25</span>) <span class="sc">|&gt;</span></span>
<span id="cb42-22"><a href="#cb42-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb42-23"><a href="#cb42-23" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb42-24"><a href="#cb42-24" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb42-25"><a href="#cb42-25" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb42-26"><a href="#cb42-26" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb42-27"><a href="#cb42-27" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb42-28"><a href="#cb42-28" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb42-29"><a href="#cb42-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb42-30"><a href="#cb42-30" aria-hidden="true" tabindex="-1"></a>t_1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-84330f46{}.cl-842c9ee0{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-842c9eea{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-842f417c{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-842f577a{width:1.25in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-842f5784{width:1.25in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-842f5798{width:1.25in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-84330f46"><thead><tr style="overflow-wrap:break-word;"><th class="cl-842f577a"><p class="cl-842f417c"><span class="cl-842c9ee0">Donor gender</span></p></th><th class="cl-842f577a"><p class="cl-842f417c"><span class="cl-842c9ee0">Accountant gender</span></p></th><th class="cl-842f577a"><p class="cl-842f417c"><span class="cl-842c9ee0">Transfer amount (BRL)</span></p></th><th class="cl-842f577a"><p class="cl-842f417c"><span class="cl-842c9ee0">% (rel. total)</span></p></th><th class="cl-842f577a"><p class="cl-842f417c"><span class="cl-842c9ee0">% (rel. donor gender)</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">Men</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">Men</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">109,704,048</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">69.5%</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">84.4%</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">Men</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">Women</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">20,287,761</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">12.8%</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">15.6%</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">Women</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">Men</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">10,613,090</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">6.7%</span></p></td><td class="cl-842f5784"><p class="cl-842f417c"><span class="cl-842c9eea">38.0%</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-842f5798"><p class="cl-842f417c"><span class="cl-842c9eea">Women</span></p></td><td class="cl-842f5798"><p class="cl-842f417c"><span class="cl-842c9eea">Women</span></p></td><td class="cl-842f5798"><p class="cl-842f417c"><span class="cl-842c9eea">17,299,704</span></p></td><td class="cl-842f5798"><p class="cl-842f417c"><span class="cl-842c9eea">11.0%</span></p></td><td class="cl-842f5798"><p class="cl-842f417c"><span class="cl-842c9eea">62.0%</span></p></td></tr></tbody></table></div>
</div>
</div>
<p>Save table 1 (XLSX and DOCX format)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a><span class="co"># XLSX</span></span>
<span id="cb43-2"><a href="#cb43-2" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(d_t_1, </span>
<span id="cb43-3"><a href="#cb43-3" aria-hidden="true" tabindex="-1"></a>           <span class="st">'..//Tabelas//Paper_Table_1_Dataset.xlsx'</span>)</span>
<span id="cb43-4"><a href="#cb43-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb43-5"><a href="#cb43-5" aria-hidden="true" tabindex="-1"></a><span class="co"># DOCX</span></span>
<span id="cb43-6"><a href="#cb43-6" aria-hidden="true" tabindex="-1"></a>path <span class="ot">&lt;-</span> <span class="st">'..//Tabelas/Paper_Table_1_R.docx'</span></span>
<span id="cb43-7"><a href="#cb43-7" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb43-8"><a href="#cb43-8" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value=</span>t_1)</span>
<span id="cb43-9"><a href="#cb43-9" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="table-2---transfer-of-funds-between-candidates-by-race" class="level3">
<h3 class="anchored" data-anchor-id="table-2---transfer-of-funds-between-candidates-by-race">Table 2 - Transfer of funds between candidates, by race</h3>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>Here, we consider only funding originating from public revenue. The candidate who donates is called the donor, and the candidate who receives the donation is called the accountant.</p>
</div>
</div>
<p>Create dataset for table 2</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb44"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a>d_t_2 <span class="ot">&lt;-</span> receitas <span class="sc">%&gt;%</span></span>
<span id="cb44-2"><a href="#cb44-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2022</span>,</span>
<span id="cb44-3"><a href="#cb44-3" aria-hidden="true" tabindex="-1"></a>         NR_CPF_CNPJ_DOADOR <span class="sc">!=</span> NR_CNPJ_PRESTADOR_CONTA,</span>
<span id="cb44-4"><a href="#cb44-4" aria-hidden="true" tabindex="-1"></a>         DS_FONTE_RECURSO <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'Recursos de outros candidatos'</span>, </span>
<span id="cb44-5"><a href="#cb44-5" aria-hidden="true" tabindex="-1"></a>                                 <span class="st">'Recursos de partido político'</span>),</span>
<span id="cb44-6"><a href="#cb44-6" aria-hidden="true" tabindex="-1"></a>         tipo_recurso <span class="sc">==</span> <span class="st">'Public'</span>,</span>
<span id="cb44-7"><a href="#cb44-7" aria-hidden="true" tabindex="-1"></a>         cor_raca_doador <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'White'</span>, <span class="st">'Black'</span>),</span>
<span id="cb44-8"><a href="#cb44-8" aria-hidden="true" tabindex="-1"></a>         cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'White'</span>, <span class="st">'Black'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb44-9"><a href="#cb44-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb44-10"><a href="#cb44-10" aria-hidden="true" tabindex="-1"></a>         <span class="at">position =</span> DS_CARGO,</span>
<span id="cb44-11"><a href="#cb44-11" aria-hidden="true" tabindex="-1"></a>         <span class="at">gender =</span> genero,</span>
<span id="cb44-12"><a href="#cb44-12" aria-hidden="true" tabindex="-1"></a>         <span class="at">gender_donor =</span> genero_doador,</span>
<span id="cb44-13"><a href="#cb44-13" aria-hidden="true" tabindex="-1"></a>         <span class="at">race_donor =</span> cor_raca_doador,</span>
<span id="cb44-14"><a href="#cb44-14" aria-hidden="true" tabindex="-1"></a>         <span class="at">race_accountant =</span> cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb44-15"><a href="#cb44-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span><span class="fu">c</span>(ano_eleicao, DS_CARGO, genero, genero_doador,</span>
<span id="cb44-16"><a href="#cb44-16" aria-hidden="true" tabindex="-1"></a>            cor_raca, cor_raca_doador)) <span class="sc">%&gt;%</span></span>
<span id="cb44-17"><a href="#cb44-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(race_donor, race_accountant) <span class="sc">%&gt;%</span></span>
<span id="cb44-18"><a href="#cb44-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">transfers_between_accountants =</span> <span class="fu">sum</span>(TOTAL_RECEITA),</span>
<span id="cb44-19"><a href="#cb44-19" aria-hidden="true" tabindex="-1"></a>            <span class="at">.groups =</span> <span class="st">'drop'</span>) <span class="sc">%&gt;%</span></span>
<span id="cb44-20"><a href="#cb44-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb44-21"><a href="#cb44-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(race_donor) <span class="sc">%&gt;%</span></span>
<span id="cb44-22"><a href="#cb44-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb44-23"><a href="#cb44-23" aria-hidden="true" tabindex="-1"></a>    <span class="at">prc_transfers_rel_race_donor =</span> transfers_between_accountants <span class="sc">/</span> </span>
<span id="cb44-24"><a href="#cb44-24" aria-hidden="true" tabindex="-1"></a>        <span class="fu">sum</span>(transfers_between_accountants)) <span class="sc">%&gt;%</span></span>
<span id="cb44-25"><a href="#cb44-25" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb44-26"><a href="#cb44-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb44-27"><a href="#cb44-27" aria-hidden="true" tabindex="-1"></a>      <span class="at">prc_transfers_rel_total =</span> transfers_between_accountants <span class="sc">/</span> </span>
<span id="cb44-28"><a href="#cb44-28" aria-hidden="true" tabindex="-1"></a>        <span class="fu">sum</span>(transfers_between_accountants)) <span class="sc">%&gt;%</span></span>
<span id="cb44-29"><a href="#cb44-29" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(race_donor, race_accountant, </span>
<span id="cb44-30"><a href="#cb44-30" aria-hidden="true" tabindex="-1"></a>         transfers_between_accountants,</span>
<span id="cb44-31"><a href="#cb44-31" aria-hidden="true" tabindex="-1"></a>         prc_transfers_rel_total,</span>
<span id="cb44-32"><a href="#cb44-32" aria-hidden="true" tabindex="-1"></a>         prc_transfers_rel_race_donor) <span class="sc">%&gt;%</span></span>
<span id="cb44-33"><a href="#cb44-33" aria-hidden="true" tabindex="-1"></a>  <span class="fu">as_tibble</span>()</span>
<span id="cb44-34"><a href="#cb44-34" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-35"><a href="#cb44-35" aria-hidden="true" tabindex="-1"></a>d_t_2</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":["race_donor"],"name":[1],"type":["chr"],"align":["left"]},{"label":["race_accountant"],"name":[2],"type":["chr"],"align":["left"]},{"label":["transfers_between_accountants"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["prc_transfers_rel_total"],"name":[4],"type":["dbl"],"align":["right"]},{"label":["prc_transfers_rel_race_donor"],"name":[5],"type":["dbl"],"align":["right"]}],"data":[{"1":"Black","2":"Black","3":"29364609","4":"0.1905465","5":"0.6542172"},{"1":"Black","2":"White","3":"15520501","4":"0.1007123","5":"0.3457828"},{"1":"White","2":"Black","3":"32186781","4":"0.2088595","5":"0.2946908"},{"1":"White","2":"White","3":"77035431","4":"0.4998817","5":"0.7053092"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
<p>Plot table 2 (HTML format)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb45"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a>t_2 <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(d_t_2) <span class="sc">|&gt;</span></span>
<span id="cb45-2"><a href="#cb45-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">delete_part</span>(<span class="st">"foot"</span>) <span class="sc">|&gt;</span></span>
<span id="cb45-3"><a href="#cb45-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">delete_rows</span>(<span class="at">i =</span> <span class="dv">2</span>, <span class="at">part =</span> <span class="st">"header"</span>) <span class="sc">|&gt;</span></span>
<span id="cb45-4"><a href="#cb45-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mk_par</span>(</span>
<span id="cb45-5"><a href="#cb45-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">j =</span> <span class="dv">4</span>, <span class="at">part =</span> <span class="st">"body"</span>,</span>
<span id="cb45-6"><a href="#cb45-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">value =</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_transfers_rel_total,</span>
<span id="cb45-7"><a href="#cb45-7" aria-hidden="true" tabindex="-1"></a>                                  <span class="at">formatter =</span> fmt_pct))) <span class="sc">|&gt;</span></span>
<span id="cb45-8"><a href="#cb45-8" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mk_par</span>(</span>
<span id="cb45-9"><a href="#cb45-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">j =</span> <span class="dv">5</span>, <span class="at">part =</span> <span class="st">"body"</span>,</span>
<span id="cb45-10"><a href="#cb45-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">value =</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_transfers_rel_race_donor,</span>
<span id="cb45-11"><a href="#cb45-11" aria-hidden="true" tabindex="-1"></a>                                  <span class="at">formatter =</span> fmt_pct))) <span class="sc">|&gt;</span></span>
<span id="cb45-12"><a href="#cb45-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb45-13"><a href="#cb45-13" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb45-14"><a href="#cb45-14" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb45-15"><a href="#cb45-15" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_accountant"</span> <span class="ot">=</span> <span class="st">"Accountant race/color"</span>,</span>
<span id="cb45-16"><a href="#cb45-16" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_donor"</span> <span class="ot">=</span> <span class="st">"Donor race/color"</span>,</span>
<span id="cb45-17"><a href="#cb45-17" aria-hidden="true" tabindex="-1"></a>      <span class="st">"transfers_between_accountants"</span> <span class="ot">=</span> <span class="st">"Transfer amount (BRL)"</span>,</span>
<span id="cb45-18"><a href="#cb45-18" aria-hidden="true" tabindex="-1"></a>      <span class="st">"prc_transfers_rel_total"</span> <span class="ot">=</span> <span class="st">"% (rel. total)"</span>,</span>
<span id="cb45-19"><a href="#cb45-19" aria-hidden="true" tabindex="-1"></a>      <span class="st">"prc_transfers_rel_race_donor"</span> <span class="ot">=</span> <span class="st">"% (rel. donor race/color)"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb45-20"><a href="#cb45-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb45-21"><a href="#cb45-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">1.25</span>) <span class="sc">|&gt;</span></span>
<span id="cb45-22"><a href="#cb45-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb45-23"><a href="#cb45-23" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb45-24"><a href="#cb45-24" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb45-25"><a href="#cb45-25" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb45-26"><a href="#cb45-26" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb45-27"><a href="#cb45-27" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb45-28"><a href="#cb45-28" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb45-29"><a href="#cb45-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb45-30"><a href="#cb45-30" aria-hidden="true" tabindex="-1"></a>t_2</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-84d48c04{}.cl-84cce8c8{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-84cce8d2{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-84d020e2{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-84d031f4{width:1.25in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-84d031f5{width:1.25in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-84d031fe{width:1.25in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-84d48c04"><thead><tr style="overflow-wrap:break-word;"><th class="cl-84d031f4"><p class="cl-84d020e2"><span class="cl-84cce8c8">Donor race/color</span></p></th><th class="cl-84d031f4"><p class="cl-84d020e2"><span class="cl-84cce8c8">Accountant race/color</span></p></th><th class="cl-84d031f4"><p class="cl-84d020e2"><span class="cl-84cce8c8">Transfer amount (BRL)</span></p></th><th class="cl-84d031f4"><p class="cl-84d020e2"><span class="cl-84cce8c8">% (rel. total)</span></p></th><th class="cl-84d031f4"><p class="cl-84d020e2"><span class="cl-84cce8c8">% (rel. donor race/color)</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">Black</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">Black</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">29,364,609</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">19.1%</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">65.4%</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">Black</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">White</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">15,520,501</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">10.1%</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">34.6%</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">White</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">Black</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">32,186,781</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">20.9%</span></p></td><td class="cl-84d031f5"><p class="cl-84d020e2"><span class="cl-84cce8d2">29.5%</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-84d031fe"><p class="cl-84d020e2"><span class="cl-84cce8d2">White</span></p></td><td class="cl-84d031fe"><p class="cl-84d020e2"><span class="cl-84cce8d2">White</span></p></td><td class="cl-84d031fe"><p class="cl-84d020e2"><span class="cl-84cce8d2">77,035,431</span></p></td><td class="cl-84d031fe"><p class="cl-84d020e2"><span class="cl-84cce8d2">50.0%</span></p></td><td class="cl-84d031fe"><p class="cl-84d020e2"><span class="cl-84cce8d2">70.5%</span></p></td></tr></tbody></table></div>
</div>
</div>
<p>Save table 2 (XLSX and DOCX)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a><span class="co"># XLSX</span></span>
<span id="cb46-2"><a href="#cb46-2" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(d_t_2, </span>
<span id="cb46-3"><a href="#cb46-3" aria-hidden="true" tabindex="-1"></a>           <span class="st">'..//Tabelas//Paper_Table_2_Dataset.xlsx'</span>)</span>
<span id="cb46-4"><a href="#cb46-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb46-5"><a href="#cb46-5" aria-hidden="true" tabindex="-1"></a><span class="co"># DOCX</span></span>
<span id="cb46-6"><a href="#cb46-6" aria-hidden="true" tabindex="-1"></a>path <span class="ot">&lt;-</span> <span class="st">'..//Tabelas/Paper_Table_2_R.docx'</span></span>
<span id="cb46-7"><a href="#cb46-7" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb46-8"><a href="#cb46-8" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_2)</span>
<span id="cb46-9"><a href="#cb46-9" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
</section>
<section id="transfers-and-reelection" class="level2">
<h2 class="anchored" data-anchor-id="transfers-and-reelection">Transfers and Reelection</h2>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>In this work, we consider only funding originating from public revenues.</p>
<p>Only the transformed variables presented in the tables below were translated; the others were kept in Portuguese.</p>
</div>
</div>
<section id="create-dataset-for-tables-3-and-4" class="level3">
<h3 class="anchored" data-anchor-id="create-dataset-for-tables-3-and-4">Create dataset for Tables 3 and 4</h3>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb47"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a>d_tables_3_4 <span class="ot">&lt;-</span> receitas_publicas <span class="sc">%&gt;%</span> </span>
<span id="cb47-2"><a href="#cb47-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb47-3"><a href="#cb47-3" aria-hidden="true" tabindex="-1"></a>    cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>),</span>
<span id="cb47-4"><a href="#cb47-4" aria-hidden="true" tabindex="-1"></a>    genero <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"Men"</span>, <span class="st">"Women"</span>),</span>
<span id="cb47-5"><a href="#cb47-5" aria-hidden="true" tabindex="-1"></a>    cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO FEDERAL'</span>,</span>
<span id="cb47-6"><a href="#cb47-6" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO DISTRITAL'</span>,</span>
<span id="cb47-7"><a href="#cb47-7" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO ESTADUAL'</span>)</span>
<span id="cb47-8"><a href="#cb47-8" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">%&gt;%</span></span>
<span id="cb47-9"><a href="#cb47-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb47-10"><a href="#cb47-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb47-11"><a href="#cb47-11" aria-hidden="true" tabindex="-1"></a>    <span class="at">race_color =</span> cor_raca,</span>
<span id="cb47-12"><a href="#cb47-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">gender =</span> genero,</span>
<span id="cb47-13"><a href="#cb47-13" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">ifelse</span>(cargo <span class="sc">==</span> <span class="st">"DEPUTADO DISTRITAL"</span>, </span>
<span id="cb47-14"><a href="#cb47-14" aria-hidden="true" tabindex="-1"></a>                      <span class="st">"DEPUTADO ESTADUAL"</span>, </span>
<span id="cb47-15"><a href="#cb47-15" aria-hidden="true" tabindex="-1"></a>                      cargo),</span>
<span id="cb47-16"><a href="#cb47-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">dispute_status =</span> <span class="fu">ifelse</span>(reeleicao <span class="sc">==</span> <span class="st">"Reelection"</span>,</span>
<span id="cb47-17"><a href="#cb47-17" aria-hidden="true" tabindex="-1"></a>                            <span class="st">"Incumbent"</span>,</span>
<span id="cb47-18"><a href="#cb47-18" aria-hidden="true" tabindex="-1"></a>                            reeleicao)</span>
<span id="cb47-19"><a href="#cb47-19" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">%&gt;%</span></span>
<span id="cb47-20"><a href="#cb47-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span><span class="fu">c</span>(ano_eleicao, cor_raca, genero, cargo, reeleicao)) <span class="sc">%&gt;%</span></span>
<span id="cb47-21"><a href="#cb47-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(position, year_election, gender, race_color, dispute_status) <span class="sc">%&gt;%</span></span>
<span id="cb47-22"><a href="#cb47-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(</span>
<span id="cb47-23"><a href="#cb47-23" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receita_grupo =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb47-24"><a href="#cb47-24" aria-hidden="true" tabindex="-1"></a>    <span class="at">qtd_cand_grupo =</span> <span class="fu">n_distinct</span>(cpf_candidato),</span>
<span id="cb47-25"><a href="#cb47-25" aria-hidden="true" tabindex="-1"></a>    <span class="at">.groups =</span> <span class="st">"drop"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb47-26"><a href="#cb47-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb47-27"><a href="#cb47-27" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(position, year_election) <span class="sc">%&gt;%</span></span>
<span id="cb47-28"><a href="#cb47-28" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb47-29"><a href="#cb47-29" aria-hidden="true" tabindex="-1"></a>    <span class="at">prc_rvn =</span> total_receita_grupo <span class="sc">/</span> <span class="fu">sum</span>(total_receita_grupo, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb47-30"><a href="#cb47-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">prc_cnd =</span> qtd_cand_grupo <span class="sc">/</span> <span class="fu">sum</span>(qtd_cand_grupo, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb47-31"><a href="#cb47-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">avg_rvn =</span> total_receita_grupo <span class="sc">/</span>  qtd_cand_grupo) <span class="sc">%&gt;%</span></span>
<span id="cb47-32"><a href="#cb47-32" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(</span>
<span id="cb47-33"><a href="#cb47-33" aria-hidden="true" tabindex="-1"></a>    position, year_election, gender, race_color, dispute_status, </span>
<span id="cb47-34"><a href="#cb47-34" aria-hidden="true" tabindex="-1"></a>    prc_cnd, prc_rvn, avg_rvn)</span>
<span id="cb47-35"><a href="#cb47-35" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb47-36"><a href="#cb47-36" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(d_tables_3_4)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":["position"],"name":[1],"type":["chr"],"align":["left"]},{"label":["year_election"],"name":[2],"type":["fct"],"align":["left"]},{"label":["gender"],"name":[3],"type":["chr"],"align":["left"]},{"label":["race_color"],"name":[4],"type":["chr"],"align":["left"]},{"label":["dispute_status"],"name":[5],"type":["chr"],"align":["left"]},{"label":["prc_cnd"],"name":[6],"type":["dbl"],"align":["right"]},{"label":["prc_rvn"],"name":[7],"type":["dbl"],"align":["right"]},{"label":["avg_rvn"],"name":[8],"type":["dbl"],"align":["right"]}],"data":[{"1":"DEPUTADO ESTADUAL","2":"2018","3":"Men","4":"Black","5":"Challenger","6":"0.304180280","7":"0.13289370","8":"20896.40"},{"1":"DEPUTADO ESTADUAL","2":"2018","3":"Men","4":"Black","5":"Incumbent","6":"0.014744073","7":"0.04756254","8":"154292.83"},{"1":"DEPUTADO ESTADUAL","2":"2018","3":"Men","4":"White","5":"Challenger","6":"0.290273938","7":"0.22976710","8":"37859.77"},{"1":"DEPUTADO ESTADUAL","2":"2018","3":"Men","4":"White","5":"Incumbent","6":"0.038870738","7":"0.13908187","8":"171137.79"},{"1":"DEPUTADO ESTADUAL","2":"2018","3":"Women","4":"Black","5":"Challenger","6":"0.174164363","7":"0.14822296","8":"40705.62"},{"1":"DEPUTADO ESTADUAL","2":"2018","3":"Women","4":"Black","5":"Incumbent","6":"0.002764514","7":"0.01926615","8":"333329.98"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
</section>
<section id="table-3---proportion-and-average-funds-of-candidates-for-federal-deputy-by-gender-race-and-dispute-status-challenger-x-incumbent" class="level3">
<h3 class="anchored" data-anchor-id="table-3---proportion-and-average-funds-of-candidates-for-federal-deputy-by-gender-race-and-dispute-status-challenger-x-incumbent">Table 3 - Proportion and average funds of candidates for federal deputy by gender, race and dispute status (challenger x incumbent)</h3>
<p>Plot Table 3 - panel “a”: Federal Deputy - 2018</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb48"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb48-1"><a href="#cb48-1" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2018</span></span>
<span id="cb48-2"><a href="#cb48-2" aria-hidden="true" tabindex="-1"></a>t_3_a <span class="ot">&lt;-</span> d_tables_3_4 <span class="sc">%&gt;%</span></span>
<span id="cb48-3"><a href="#cb48-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb48-4"><a href="#cb48-4" aria-hidden="true" tabindex="-1"></a>         position <span class="sc">==</span> <span class="st">"DEPUTADO FEDERAL"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb48-5"><a href="#cb48-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb48-6"><a href="#cb48-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb48-7"><a href="#cb48-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="st">"dispute_status"</span>,</span>
<span id="cb48-8"><a href="#cb48-8" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Candidate (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_cnd, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb48-9"><a href="#cb48-9" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_rvn, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb48-10"><a href="#cb48-10" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(avg_rvn,</span>
<span id="cb48-11"><a href="#cb48-11" aria-hidden="true" tabindex="-1"></a>                                                 <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb48-12"><a href="#cb48-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb48-13"><a href="#cb48-13" aria-hidden="true" tabindex="-1"></a>t_3_a <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_3_a) <span class="sc">%&gt;%</span></span>
<span id="cb48-14"><a href="#cb48-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb48-15"><a href="#cb48-15" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb48-16"><a href="#cb48-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb48-17"><a href="#cb48-17" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb48-18"><a href="#cb48-18" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb48-19"><a href="#cb48-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb48-20"><a href="#cb48-20" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb48-21"><a href="#cb48-21" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb48-22"><a href="#cb48-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb48-23"><a href="#cb48-23" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb48-24"><a href="#cb48-24" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb48-25"><a href="#cb48-25" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb48-26"><a href="#cb48-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb48-27"><a href="#cb48-27" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb48-28"><a href="#cb48-28" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb48-29"><a href="#cb48-29" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb48-30"><a href="#cb48-30" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb48-31"><a href="#cb48-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb48-32"><a href="#cb48-32" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb48-33"><a href="#cb48-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb48-34"><a href="#cb48-34" aria-hidden="true" tabindex="-1"></a>t_3_a</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-85d7f7f8{}.cl-85cf62fa{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-85cf6304{font-family:'Arial';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-85cf630e{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-85d1fb00{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-85d1fb0a{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-85d1fb14{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-85d1fb1e{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-85d1fb28{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-85d210d6{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-85d210e0{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-85d210ea{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0.75pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-85d210eb{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-85d210f4{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0.75pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-85d210f5{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-85d210f6{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-85d7f7f8"><thead><tr style="overflow-wrap:break-word;"><th rowspan="2" class="cl-85d210d6"><p class="cl-85d1fb00"><span class="cl-85cf62fa">Gender</span></p></th><th rowspan="2" class="cl-85d210d6"><p class="cl-85d1fb00"><span class="cl-85cf62fa">Race/color</span></p></th><th class="cl-85d210e0"><p class="cl-85d1fb0a"><span class="cl-85cf6304"></span></p></th><th colspan="3" class="cl-85d210ea"><p class="cl-85d1fb14"><span class="cl-85cf62fa">Challenger</span></p></th><th class="cl-85d210e0"><p class="cl-85d1fb0a"><span class="cl-85cf6304"></span></p></th><th colspan="3" class="cl-85d210ea"><p class="cl-85d1fb14"><span class="cl-85cf62fa">Incumbent</span></p></th></tr><tr style="overflow-wrap:break-word;"><th class="cl-85d210e0"><p class="cl-85d1fb0a"><span class="cl-85cf6304"></span></p></th><th class="cl-85d210f4"><p class="cl-85d1fb14"><span class="cl-85cf62fa">Candidate (%)</span></p></th><th class="cl-85d210f4"><p class="cl-85d1fb14"><span class="cl-85cf62fa">Revenue (%)</span></p></th><th class="cl-85d210f4"><p class="cl-85d1fb14"><span class="cl-85cf62fa">Revenue avg. (BRL)</span></p></th><th class="cl-85d210e0"><p class="cl-85d1fb0a"><span class="cl-85cf6304"></span></p></th><th class="cl-85d210f4"><p class="cl-85d1fb14"><span class="cl-85cf62fa">Candidate (%)</span></p></th><th class="cl-85d210f4"><p class="cl-85d1fb14"><span class="cl-85cf62fa">Revenue (%)</span></p></th><th class="cl-85d210f4"><p class="cl-85d1fb14"><span class="cl-85cf62fa">Revenue avg. (BRL)</span></p></th></tr><tr style="overflow-wrap:break-word;"><th colspan="10" class="cl-85d210eb"><p class="cl-85d1fb00"><span class="cl-85cf62fa">2018</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">Men</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">Black</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb28"><span class="cl-85cf6304"></span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">24.5%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">9.2%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">70,936</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb28"><span class="cl-85cf6304"></span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">1.4%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">7.7%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">1,018,757</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">White</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb28"><span class="cl-85cf6304"></span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">34.0%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">25.3%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">140,258</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb28"><span class="cl-85cf6304"></span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">5.1%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">32.4%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">1,201,292</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-85d210f6"><p class="cl-85d1fb1e"><span class="cl-85cf630e">Women</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">Black</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb28"><span class="cl-85cf6304"></span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">15.2%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">5.3%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">65,383</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb28"><span class="cl-85cf6304"></span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">0.2%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">1.7%</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb1e"><span class="cl-85cf630e">1,733,223</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-85d210f6"><p class="cl-85d1fb1e"><span class="cl-85cf630e">White</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb28"><span class="cl-85cf6304"></span></p></td><td class="cl-85d210f6"><p class="cl-85d1fb1e"><span class="cl-85cf630e">19.0%</span></p></td><td class="cl-85d210f6"><p class="cl-85d1fb1e"><span class="cl-85cf630e">12.4%</span></p></td><td class="cl-85d210f6"><p class="cl-85d1fb1e"><span class="cl-85cf630e">123,644</span></p></td><td class="cl-85d210f5"><p class="cl-85d1fb28"><span class="cl-85cf6304"></span></p></td><td class="cl-85d210f6"><p class="cl-85d1fb1e"><span class="cl-85cf630e">0.7%</span></p></td><td class="cl-85d210f6"><p class="cl-85d1fb1e"><span class="cl-85cf630e">5.9%</span></p></td><td class="cl-85d210f6"><p class="cl-85d1fb1e"><span class="cl-85cf630e">1,678,770</span></p></td></tr></tbody></table></div>
</div>
</div>
<p>Format Table 3 - panel “b”: Federal Deputy - 2022</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb49"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb49-1"><a href="#cb49-1" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2022</span></span>
<span id="cb49-2"><a href="#cb49-2" aria-hidden="true" tabindex="-1"></a>t_3_b <span class="ot">&lt;-</span> d_tables_3_4 <span class="sc">%&gt;%</span></span>
<span id="cb49-3"><a href="#cb49-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb49-4"><a href="#cb49-4" aria-hidden="true" tabindex="-1"></a>         position <span class="sc">==</span> <span class="st">"DEPUTADO FEDERAL"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb49-5"><a href="#cb49-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb49-6"><a href="#cb49-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb49-7"><a href="#cb49-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="st">"dispute_status"</span>,</span>
<span id="cb49-8"><a href="#cb49-8" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Candidate (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_cnd, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb49-9"><a href="#cb49-9" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_rvn, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb49-10"><a href="#cb49-10" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(avg_rvn,</span>
<span id="cb49-11"><a href="#cb49-11" aria-hidden="true" tabindex="-1"></a>                                                 <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb49-12"><a href="#cb49-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb49-13"><a href="#cb49-13" aria-hidden="true" tabindex="-1"></a>t_3_b <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_3_b) <span class="sc">%&gt;%</span></span>
<span id="cb49-14"><a href="#cb49-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb49-15"><a href="#cb49-15" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb49-16"><a href="#cb49-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb49-17"><a href="#cb49-17" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb49-18"><a href="#cb49-18" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb49-19"><a href="#cb49-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb49-20"><a href="#cb49-20" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb49-21"><a href="#cb49-21" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb49-22"><a href="#cb49-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb49-23"><a href="#cb49-23" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb49-24"><a href="#cb49-24" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb49-25"><a href="#cb49-25" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb49-26"><a href="#cb49-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb49-27"><a href="#cb49-27" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb49-28"><a href="#cb49-28" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb49-29"><a href="#cb49-29" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb49-30"><a href="#cb49-30" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb49-31"><a href="#cb49-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb49-32"><a href="#cb49-32" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb49-33"><a href="#cb49-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb49-34"><a href="#cb49-34" aria-hidden="true" tabindex="-1"></a>t_3_b</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-860a08c4{}.cl-86036aaa{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-86036ab4{font-family:'Arial';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-86036abe{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-860612a0{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-860612be{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-860612bf{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-860612c8{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-860612c9{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-860626a0{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-860626aa{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-860626ab{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0.75pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-860626b4{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-860626be{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0.75pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-860626bf{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-860626c8{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-860a08c4"><thead><tr style="overflow-wrap:break-word;"><th rowspan="2" class="cl-860626a0"><p class="cl-860612a0"><span class="cl-86036aaa">Gender</span></p></th><th rowspan="2" class="cl-860626a0"><p class="cl-860612a0"><span class="cl-86036aaa">Race/color</span></p></th><th class="cl-860626aa"><p class="cl-860612be"><span class="cl-86036ab4"></span></p></th><th colspan="3" class="cl-860626ab"><p class="cl-860612bf"><span class="cl-86036aaa">Challenger</span></p></th><th class="cl-860626aa"><p class="cl-860612be"><span class="cl-86036ab4"></span></p></th><th colspan="3" class="cl-860626ab"><p class="cl-860612bf"><span class="cl-86036aaa">Incumbent</span></p></th></tr><tr style="overflow-wrap:break-word;"><th class="cl-860626aa"><p class="cl-860612be"><span class="cl-86036ab4"></span></p></th><th class="cl-860626be"><p class="cl-860612bf"><span class="cl-86036aaa">Candidate (%)</span></p></th><th class="cl-860626be"><p class="cl-860612bf"><span class="cl-86036aaa">Revenue (%)</span></p></th><th class="cl-860626be"><p class="cl-860612bf"><span class="cl-86036aaa">Revenue avg. (BRL)</span></p></th><th class="cl-860626aa"><p class="cl-860612be"><span class="cl-86036ab4"></span></p></th><th class="cl-860626be"><p class="cl-860612bf"><span class="cl-86036aaa">Candidate (%)</span></p></th><th class="cl-860626be"><p class="cl-860612bf"><span class="cl-86036aaa">Revenue (%)</span></p></th><th class="cl-860626be"><p class="cl-860612bf"><span class="cl-86036aaa">Revenue avg. (BRL)</span></p></th></tr><tr style="overflow-wrap:break-word;"><th colspan="10" class="cl-860626b4"><p class="cl-860612a0"><span class="cl-86036aaa">2022</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">Men</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">Black</span></p></td><td class="cl-860626bf"><p class="cl-860612c9"><span class="cl-86036ab4"></span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">28.2%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">16.8%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">202,443</span></p></td><td class="cl-860626bf"><p class="cl-860612c9"><span class="cl-86036ab4"></span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">1.2%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">6.9%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">1,913,636</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">White</span></p></td><td class="cl-860626bf"><p class="cl-860612c9"><span class="cl-86036ab4"></span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">30.6%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">26.7%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">296,833</span></p></td><td class="cl-860626bf"><p class="cl-860612c9"><span class="cl-86036ab4"></span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">3.3%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">17.8%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">1,812,449</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-860626c8"><p class="cl-860612c8"><span class="cl-86036abe">Women</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">Black</span></p></td><td class="cl-860626bf"><p class="cl-860612c9"><span class="cl-86036ab4"></span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">19.2%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">13.4%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">237,442</span></p></td><td class="cl-860626bf"><p class="cl-860612c9"><span class="cl-86036ab4"></span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">0.2%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">1.1%</span></p></td><td class="cl-860626bf"><p class="cl-860612c8"><span class="cl-86036abe">1,927,331</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-860626c8"><p class="cl-860612c8"><span class="cl-86036abe">White</span></p></td><td class="cl-860626bf"><p class="cl-860612c9"><span class="cl-86036ab4"></span></p></td><td class="cl-860626c8"><p class="cl-860612c8"><span class="cl-86036abe">16.6%</span></p></td><td class="cl-860626c8"><p class="cl-860612c8"><span class="cl-86036abe">13.8%</span></p></td><td class="cl-860626c8"><p class="cl-860612c8"><span class="cl-86036abe">282,818</span></p></td><td class="cl-860626bf"><p class="cl-860612c9"><span class="cl-86036ab4"></span></p></td><td class="cl-860626c8"><p class="cl-860612c8"><span class="cl-86036abe">0.6%</span></p></td><td class="cl-860626c8"><p class="cl-860612c8"><span class="cl-86036abe">3.5%</span></p></td><td class="cl-860626c8"><p class="cl-860612c8"><span class="cl-86036abe">2,135,871</span></p></td></tr></tbody></table></div>
</div>
</div>
<p>Save table 3, panels “a” and “b”, in DOCX format</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb50"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb50-1"><a href="#cb50-1" aria-hidden="true" tabindex="-1"></a>path <span class="ot">&lt;-</span> <span class="st">'..//Tabelas/Paper_Table_3_R.docx'</span></span>
<span id="cb50-2"><a href="#cb50-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb50-3"><a href="#cb50-3" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb50-4"><a href="#cb50-4" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value=</span>t_3_a)</span>
<span id="cb50-5"><a href="#cb50-5" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value=</span>t_3_b)</span>
<span id="cb50-6"><a href="#cb50-6" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="table-4---proportion-and-average-funds-of-candidates-for-state-deputy-by-gender-race-and-dispute-status-challenger-x-incumbent" class="level3">
<h3 class="anchored" data-anchor-id="table-4---proportion-and-average-funds-of-candidates-for-state-deputy-by-gender-race-and-dispute-status-challenger-x-incumbent">Table 4 - Proportion and average funds of candidates for state deputy by gender, race and dispute status (challenger x incumbent)</h3>
<p>Plot Table 4 - panel “a”: State Deputy - 2018</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb51"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2018</span></span>
<span id="cb51-2"><a href="#cb51-2" aria-hidden="true" tabindex="-1"></a>t_4_a <span class="ot">&lt;-</span> d_tables_3_4 <span class="sc">%&gt;%</span></span>
<span id="cb51-3"><a href="#cb51-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb51-4"><a href="#cb51-4" aria-hidden="true" tabindex="-1"></a>         position <span class="sc">==</span> <span class="st">"DEPUTADO ESTADUAL"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb51-5"><a href="#cb51-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb51-6"><a href="#cb51-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb51-7"><a href="#cb51-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="st">"dispute_status"</span>,</span>
<span id="cb51-8"><a href="#cb51-8" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Candidate (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_cnd, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb51-9"><a href="#cb51-9" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_rvn, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb51-10"><a href="#cb51-10" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(avg_rvn,</span>
<span id="cb51-11"><a href="#cb51-11" aria-hidden="true" tabindex="-1"></a>                                                 <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb51-12"><a href="#cb51-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb51-13"><a href="#cb51-13" aria-hidden="true" tabindex="-1"></a>t_4_a <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_4_a) <span class="sc">%&gt;%</span></span>
<span id="cb51-14"><a href="#cb51-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb51-15"><a href="#cb51-15" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb51-16"><a href="#cb51-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb51-17"><a href="#cb51-17" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb51-18"><a href="#cb51-18" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb51-19"><a href="#cb51-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb51-20"><a href="#cb51-20" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb51-21"><a href="#cb51-21" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb51-22"><a href="#cb51-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb51-23"><a href="#cb51-23" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb51-24"><a href="#cb51-24" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb51-25"><a href="#cb51-25" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb51-26"><a href="#cb51-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb51-27"><a href="#cb51-27" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb51-28"><a href="#cb51-28" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb51-29"><a href="#cb51-29" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb51-30"><a href="#cb51-30" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb51-31"><a href="#cb51-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb51-32"><a href="#cb51-32" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb51-33"><a href="#cb51-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb51-34"><a href="#cb51-34" aria-hidden="true" tabindex="-1"></a>t_4_a</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-86986970{}.cl-868f8152{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-868f8166{font-family:'Arial';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-868f8170{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-86934c88{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-86934c92{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-86934c9c{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-86934c9d{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-86934ca6{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-86935d68{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86935d72{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86935d73{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0.75pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86935d7c{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86935d86{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0.75pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86935d87{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86935d90{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-86986970"><thead><tr style="overflow-wrap:break-word;"><th rowspan="2" class="cl-86935d68"><p class="cl-86934c88"><span class="cl-868f8152">Gender</span></p></th><th rowspan="2" class="cl-86935d68"><p class="cl-86934c88"><span class="cl-868f8152">Race/color</span></p></th><th class="cl-86935d72"><p class="cl-86934c92"><span class="cl-868f8166"></span></p></th><th colspan="3" class="cl-86935d73"><p class="cl-86934c9c"><span class="cl-868f8152">Challenger</span></p></th><th class="cl-86935d72"><p class="cl-86934c92"><span class="cl-868f8166"></span></p></th><th colspan="3" class="cl-86935d73"><p class="cl-86934c9c"><span class="cl-868f8152">Incumbent</span></p></th></tr><tr style="overflow-wrap:break-word;"><th class="cl-86935d72"><p class="cl-86934c92"><span class="cl-868f8166"></span></p></th><th class="cl-86935d86"><p class="cl-86934c9c"><span class="cl-868f8152">Candidate (%)</span></p></th><th class="cl-86935d86"><p class="cl-86934c9c"><span class="cl-868f8152">Revenue (%)</span></p></th><th class="cl-86935d86"><p class="cl-86934c9c"><span class="cl-868f8152">Revenue avg. (BRL)</span></p></th><th class="cl-86935d72"><p class="cl-86934c92"><span class="cl-868f8166"></span></p></th><th class="cl-86935d86"><p class="cl-86934c9c"><span class="cl-868f8152">Candidate (%)</span></p></th><th class="cl-86935d86"><p class="cl-86934c9c"><span class="cl-868f8152">Revenue (%)</span></p></th><th class="cl-86935d86"><p class="cl-86934c9c"><span class="cl-868f8152">Revenue avg. (BRL)</span></p></th></tr><tr style="overflow-wrap:break-word;"><th colspan="10" class="cl-86935d7c"><p class="cl-86934c88"><span class="cl-868f8152">2018</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">Men</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">Black</span></p></td><td class="cl-86935d87"><p class="cl-86934ca6"><span class="cl-868f8166"></span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">30.4%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">13.3%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">20,896</span></p></td><td class="cl-86935d87"><p class="cl-86934ca6"><span class="cl-868f8166"></span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">1.5%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">4.8%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">154,293</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">White</span></p></td><td class="cl-86935d87"><p class="cl-86934ca6"><span class="cl-868f8166"></span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">29.0%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">23.0%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">37,860</span></p></td><td class="cl-86935d87"><p class="cl-86934ca6"><span class="cl-868f8166"></span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">3.9%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">13.9%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">171,138</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-86935d90"><p class="cl-86934c9d"><span class="cl-868f8170">Women</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">Black</span></p></td><td class="cl-86935d87"><p class="cl-86934ca6"><span class="cl-868f8166"></span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">17.4%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">14.8%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">40,706</span></p></td><td class="cl-86935d87"><p class="cl-86934ca6"><span class="cl-868f8166"></span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">0.3%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">1.9%</span></p></td><td class="cl-86935d87"><p class="cl-86934c9d"><span class="cl-868f8170">333,330</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-86935d90"><p class="cl-86934c9d"><span class="cl-868f8170">White</span></p></td><td class="cl-86935d87"><p class="cl-86934ca6"><span class="cl-868f8166"></span></p></td><td class="cl-86935d90"><p class="cl-86934c9d"><span class="cl-868f8170">16.9%</span></p></td><td class="cl-86935d90"><p class="cl-86934c9d"><span class="cl-868f8170">22.8%</span></p></td><td class="cl-86935d90"><p class="cl-86934c9d"><span class="cl-868f8170">64,643</span></p></td><td class="cl-86935d87"><p class="cl-86934ca6"><span class="cl-868f8166"></span></p></td><td class="cl-86935d90"><p class="cl-86934c9d"><span class="cl-868f8170">0.6%</span></p></td><td class="cl-86935d90"><p class="cl-86934c9d"><span class="cl-868f8170">5.5%</span></p></td><td class="cl-86935d90"><p class="cl-86934c9d"><span class="cl-868f8170">434,866</span></p></td></tr></tbody></table></div>
</div>
</div>
<p>Plot Table 4 - panel “a”: State Deputy - 2022</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb52"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2022</span></span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a>t_4_b <span class="ot">&lt;-</span> d_tables_3_4 <span class="sc">%&gt;%</span></span>
<span id="cb52-3"><a href="#cb52-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb52-4"><a href="#cb52-4" aria-hidden="true" tabindex="-1"></a>         position <span class="sc">==</span> <span class="st">"DEPUTADO ESTADUAL"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb52-5"><a href="#cb52-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb52-6"><a href="#cb52-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb52-7"><a href="#cb52-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="st">"dispute_status"</span>,</span>
<span id="cb52-8"><a href="#cb52-8" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Candidate (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_cnd, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb52-9"><a href="#cb52-9" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_rvn, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb52-10"><a href="#cb52-10" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(avg_rvn,</span>
<span id="cb52-11"><a href="#cb52-11" aria-hidden="true" tabindex="-1"></a>                                                 <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb52-12"><a href="#cb52-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb52-13"><a href="#cb52-13" aria-hidden="true" tabindex="-1"></a>t_4_b <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_4_b) <span class="sc">%&gt;%</span></span>
<span id="cb52-14"><a href="#cb52-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb52-15"><a href="#cb52-15" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb52-16"><a href="#cb52-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb52-17"><a href="#cb52-17" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb52-18"><a href="#cb52-18" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb52-19"><a href="#cb52-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb52-20"><a href="#cb52-20" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb52-21"><a href="#cb52-21" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb52-22"><a href="#cb52-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb52-23"><a href="#cb52-23" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb52-24"><a href="#cb52-24" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb52-25"><a href="#cb52-25" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb52-26"><a href="#cb52-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb52-27"><a href="#cb52-27" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb52-28"><a href="#cb52-28" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb52-29"><a href="#cb52-29" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb52-30"><a href="#cb52-30" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb52-31"><a href="#cb52-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb52-32"><a href="#cb52-32" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb52-33"><a href="#cb52-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb52-34"><a href="#cb52-34" aria-hidden="true" tabindex="-1"></a>t_4_b</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-86cce2d6{}.cl-86c61230{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-86c6123a{font-family:'Arial';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-86c61244{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-86c90cb0{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-86c90cba{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-86c90cc4{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-86c90cd8{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-86c90cec{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-86c91e62{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86c91e63{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86c91e6c{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0.75pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86c91e6d{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86c91e76{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0.75pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86c91e77{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-86c91e78{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-86cce2d6"><thead><tr style="overflow-wrap:break-word;"><th rowspan="2" class="cl-86c91e62"><p class="cl-86c90cb0"><span class="cl-86c61230">Gender</span></p></th><th rowspan="2" class="cl-86c91e62"><p class="cl-86c90cb0"><span class="cl-86c61230">Race/color</span></p></th><th class="cl-86c91e63"><p class="cl-86c90cba"><span class="cl-86c6123a"></span></p></th><th colspan="3" class="cl-86c91e6c"><p class="cl-86c90cc4"><span class="cl-86c61230">Challenger</span></p></th><th class="cl-86c91e63"><p class="cl-86c90cba"><span class="cl-86c6123a"></span></p></th><th colspan="3" class="cl-86c91e6c"><p class="cl-86c90cc4"><span class="cl-86c61230">Incumbent</span></p></th></tr><tr style="overflow-wrap:break-word;"><th class="cl-86c91e63"><p class="cl-86c90cba"><span class="cl-86c6123a"></span></p></th><th class="cl-86c91e76"><p class="cl-86c90cc4"><span class="cl-86c61230">Candidate (%)</span></p></th><th class="cl-86c91e76"><p class="cl-86c90cc4"><span class="cl-86c61230">Revenue (%)</span></p></th><th class="cl-86c91e76"><p class="cl-86c90cc4"><span class="cl-86c61230">Revenue avg. (BRL)</span></p></th><th class="cl-86c91e63"><p class="cl-86c90cba"><span class="cl-86c6123a"></span></p></th><th class="cl-86c91e76"><p class="cl-86c90cc4"><span class="cl-86c61230">Candidate (%)</span></p></th><th class="cl-86c91e76"><p class="cl-86c90cc4"><span class="cl-86c61230">Revenue (%)</span></p></th><th class="cl-86c91e76"><p class="cl-86c90cc4"><span class="cl-86c61230">Revenue avg. (BRL)</span></p></th></tr><tr style="overflow-wrap:break-word;"><th colspan="10" class="cl-86c91e6d"><p class="cl-86c90cb0"><span class="cl-86c61230">2022</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">Men</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">Black</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cec"><span class="cl-86c6123a"></span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">30.9%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">20.7%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">72,140</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cec"><span class="cl-86c6123a"></span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">1.7%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">5.8%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">374,296</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">White</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cec"><span class="cl-86c6123a"></span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">28.0%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">24.4%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">93,826</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cec"><span class="cl-86c6123a"></span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">3.2%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">10.0%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">332,836</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-86c91e78"><p class="cl-86c90cd8"><span class="cl-86c61244">Women</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">Black</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cec"><span class="cl-86c6123a"></span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">19.6%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">16.7%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">91,355</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cec"><span class="cl-86c6123a"></span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">0.4%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">2.0%</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cd8"><span class="cl-86c61244">606,004</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-86c91e78"><p class="cl-86c90cd8"><span class="cl-86c61244">White</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cec"><span class="cl-86c6123a"></span></p></td><td class="cl-86c91e78"><p class="cl-86c90cd8"><span class="cl-86c61244">15.7%</span></p></td><td class="cl-86c91e78"><p class="cl-86c90cd8"><span class="cl-86c61244">16.9%</span></p></td><td class="cl-86c91e78"><p class="cl-86c90cd8"><span class="cl-86c61244">116,219</span></p></td><td class="cl-86c91e77"><p class="cl-86c90cec"><span class="cl-86c6123a"></span></p></td><td class="cl-86c91e78"><p class="cl-86c90cd8"><span class="cl-86c61244">0.6%</span></p></td><td class="cl-86c91e78"><p class="cl-86c90cd8"><span class="cl-86c61244">3.5%</span></p></td><td class="cl-86c91e78"><p class="cl-86c90cd8"><span class="cl-86c61244">601,423</span></p></td></tr></tbody></table></div>
</div>
</div>
<p>Save table 4, panels “a” and “b”, in DOCX format</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb53"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb53-1"><a href="#cb53-1" aria-hidden="true" tabindex="-1"></a>path <span class="ot">=</span> <span class="st">'..//Tabelas/Paper_Table_4_R.docx'</span></span>
<span id="cb53-2"><a href="#cb53-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb53-3"><a href="#cb53-3" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb53-4"><a href="#cb53-4" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_4_a)</span>
<span id="cb53-5"><a href="#cb53-5" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_4_b)</span>
<span id="cb53-6"><a href="#cb53-6" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
</section>
<section id="appendix-a---table-1---public-resource-transfers-between-candidate-providers-by-gender-and-race" class="level2">
<h2 class="anchored" data-anchor-id="appendix-a---table-1---public-resource-transfers-between-candidate-providers-by-gender-and-race">Appendix A - Table 1 - Public resource transfers between candidate providers, by gender and race</h2>
<p>Create dataset for Table A1</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb54"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb54-1"><a href="#cb54-1" aria-hidden="true" tabindex="-1"></a>d_table_a1 <span class="ot">&lt;-</span> receitas_publicas_especie_agr <span class="sc">%&gt;%</span></span>
<span id="cb54-2"><a href="#cb54-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(genero <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'Men'</span>, <span class="st">'Women'</span>),</span>
<span id="cb54-3"><a href="#cb54-3" aria-hidden="true" tabindex="-1"></a>         cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'White'</span>, <span class="st">'Black'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb54-4"><a href="#cb54-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb54-5"><a href="#cb54-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb54-6"><a href="#cb54-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">race_color =</span> cor_raca,</span>
<span id="cb54-7"><a href="#cb54-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">gender =</span> genero,</span>
<span id="cb54-8"><a href="#cb54-8" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">case_when</span>(</span>
<span id="cb54-9"><a href="#cb54-9" aria-hidden="true" tabindex="-1"></a>      cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"DEPUTADO DISTRITAL"</span>, </span>
<span id="cb54-10"><a href="#cb54-10" aria-hidden="true" tabindex="-1"></a>                   <span class="st">"DEPUTADO ESTADUAL"</span>) <span class="sc">~</span> <span class="st">'State Deputy'</span>,</span>
<span id="cb54-11"><a href="#cb54-11" aria-hidden="true" tabindex="-1"></a>      cargo <span class="sc">==</span> <span class="st">'DEPUTADO FEDERAL'</span> <span class="sc">~</span> <span class="st">'Federal Deputy'</span>),</span>
<span id="cb54-12"><a href="#cb54-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">rvn_kind =</span> especie_receita) <span class="sc">%&gt;%</span></span>
<span id="cb54-13"><a href="#cb54-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span><span class="fu">c</span>(ano_eleicao, cor_raca, genero, cargo, especie_receita)) <span class="sc">%&gt;%</span></span>
<span id="cb54-14"><a href="#cb54-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(year_election, position, gender, race_color,</span>
<span id="cb54-15"><a href="#cb54-15" aria-hidden="true" tabindex="-1"></a>           rvn_kind) <span class="sc">%&gt;%</span></span>
<span id="cb54-16"><a href="#cb54-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(</span>
<span id="cb54-17"><a href="#cb54-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">rvn_amount =</span> <span class="fu">sum</span>(total_rec_ano_cargo_genero_cor_especie, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb54-18"><a href="#cb54-18" aria-hidden="true" tabindex="-1"></a>    <span class="at">.groups =</span> <span class="st">"drop"</span>)</span>
<span id="cb54-19"><a href="#cb54-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb54-20"><a href="#cb54-20" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(d_table_a1)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":["year_election"],"name":[1],"type":["fct"],"align":["left"]},{"label":["position"],"name":[2],"type":["chr"],"align":["left"]},{"label":["gender"],"name":[3],"type":["chr"],"align":["left"]},{"label":["race_color"],"name":[4],"type":["chr"],"align":["left"]},{"label":["rvn_kind"],"name":[5],"type":["chr"],"align":["left"]},{"label":["rvn_amount"],"name":[6],"type":["dbl"],"align":["right"]}],"data":[{"1":"2018","2":"Federal Deputy","3":"Men","4":"Black","5":"Cash","6":"163149049"},{"1":"2018","2":"Federal Deputy","3":"Men","4":"Black","5":"Cash-equivalent","6":"9072645"},{"1":"2018","2":"Federal Deputy","3":"Men","4":"White","5":"Cash","6":"572322916"},{"1":"2018","2":"Federal Deputy","3":"Men","4":"White","5":"Cash-equivalent","6":"15826858"},{"1":"2018","2":"Federal Deputy","3":"Women","4":"Black","5":"Cash","6":"67404852"},{"1":"2018","2":"Federal Deputy","3":"Women","4":"Black","5":"Cash-equivalent","6":"3672062"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
<p>Plot Table A1</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb55"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb55-1"><a href="#cb55-1" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2018</span></span>
<span id="cb55-2"><a href="#cb55-2" aria-hidden="true" tabindex="-1"></a>t_a1_a <span class="ot">&lt;-</span> d_table_a1 <span class="sc">|&gt;</span></span>
<span id="cb55-3"><a href="#cb55-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election) <span class="sc">|&gt;</span></span>
<span id="cb55-4"><a href="#cb55-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb55-5"><a href="#cb55-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"position"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb55-6"><a href="#cb55-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"rvn_kind"</span>),</span>
<span id="cb55-7"><a href="#cb55-7" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue amount (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb55-8"><a href="#cb55-8" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(rvn_amount, <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb55-9"><a href="#cb55-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb55-10"><a href="#cb55-10" aria-hidden="true" tabindex="-1"></a>t_a1_a <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_a1_a) <span class="sc">|&gt;</span></span>
<span id="cb55-11"><a href="#cb55-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb55-12"><a href="#cb55-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb55-13"><a href="#cb55-13" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb55-14"><a href="#cb55-14" aria-hidden="true" tabindex="-1"></a>      <span class="st">"position"</span> <span class="ot">=</span> <span class="st">"Position"</span>,</span>
<span id="cb55-15"><a href="#cb55-15" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb55-16"><a href="#cb55-16" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb55-17"><a href="#cb55-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb55-18"><a href="#cb55-18" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb55-19"><a href="#cb55-19" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb55-20"><a href="#cb55-20" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb55-21"><a href="#cb55-21" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb55-22"><a href="#cb55-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb55-23"><a href="#cb55-23" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb55-24"><a href="#cb55-24" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb55-25"><a href="#cb55-25" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb55-26"><a href="#cb55-26" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb55-27"><a href="#cb55-27" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb55-28"><a href="#cb55-28" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb55-29"><a href="#cb55-29" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb55-30"><a href="#cb55-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb55-31"><a href="#cb55-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb55-32"><a href="#cb55-32" aria-hidden="true" tabindex="-1"></a>t_a1_a</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-8764f6ca{}.cl-87573508{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-8757351c{font-family:'Arial';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-87573526{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-875fb976{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-875fb98a{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-875fb98b{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-875fb994{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-875fb99e{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-875fd87a{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-875fd88e{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-875fd88f{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0.75pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-875fd898{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-875fd8a2{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-875fd8a3{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0.75pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-875fd8ac{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-875fd8ad{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-875fd8b6{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-8764f6ca"><thead><tr style="overflow-wrap:break-word;"><th rowspan="2" class="cl-875fd87a"><p class="cl-875fb976"><span class="cl-87573508">Position</span></p></th><th rowspan="2" class="cl-875fd87a"><p class="cl-875fb976"><span class="cl-87573508">Race/color</span></p></th><th class="cl-875fd88e"><p class="cl-875fb98a"><span class="cl-8757351c"></span></p></th><th colspan="3" class="cl-875fd88f"><p class="cl-875fb98b"><span class="cl-87573508">Men</span></p></th><th class="cl-875fd88e"><p class="cl-875fb98a"><span class="cl-8757351c"></span></p></th><th colspan="3" class="cl-875fd88f"><p class="cl-875fb98b"><span class="cl-87573508">Women</span></p></th></tr><tr style="overflow-wrap:break-word;"><th class="cl-875fd8a2"><p class="cl-875fb98a"><span class="cl-8757351c"></span></p></th><th class="cl-875fd8a3"><p class="cl-875fb98b"><span class="cl-87573508">Cash</span></p></th><th class="cl-875fd8a2"><p class="cl-875fb98a"><span class="cl-8757351c"></span></p></th><th class="cl-875fd8a3"><p class="cl-875fb98b"><span class="cl-87573508">Cash-equivalent</span></p></th><th class="cl-875fd8a2"><p class="cl-875fb98a"><span class="cl-8757351c"></span></p></th><th class="cl-875fd8a3"><p class="cl-875fb98b"><span class="cl-87573508">Cash</span></p></th><th class="cl-875fd8a2"><p class="cl-875fb98a"><span class="cl-8757351c"></span></p></th><th class="cl-875fd8a3"><p class="cl-875fb98b"><span class="cl-87573508">Cash-equivalent</span></p></th></tr><tr style="overflow-wrap:break-word;"><th colspan="10" class="cl-875fd898"><p class="cl-875fb976"><span class="cl-87573508">2018</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">Federal Deputy</span></p></td><td class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">Black</span></p></td><td class="cl-875fd8ac"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">163,149,049</span></p></td><td class="cl-875fd8ac"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">9,072,645</span></p></td><td class="cl-875fd8ac"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">67,404,852</span></p></td><td class="cl-875fd8ac"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">3,672,062</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">White</span></p></td><td class="cl-875fd8ac"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">572,322,916</span></p></td><td class="cl-875fd8ac"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">15,826,858</span></p></td><td class="cl-875fd8ac"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">176,705,628</span></p></td><td class="cl-875fd8ac"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ac"><p class="cl-875fb994"><span class="cl-87573526">10,464,720</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-875fd8ad"><p class="cl-875fb994"><span class="cl-87573526">State Deputy</span></p></td><td class="cl-875fd8b6"><p class="cl-875fb994"><span class="cl-87573526">Black</span></p></td><td class="cl-875fd8b6"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8b6"><p class="cl-875fb994"><span class="cl-87573526">82,460,866</span></p></td><td class="cl-875fd8b6"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8b6"><p class="cl-875fb994"><span class="cl-87573526">20,569,513</span></p></td><td class="cl-875fd8b6"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8b6"><p class="cl-875fb994"><span class="cl-87573526">84,152,913</span></p></td><td class="cl-875fd8b6"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8b6"><p class="cl-875fb994"><span class="cl-87573526">11,473,964</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-875fd8ad"><p class="cl-875fb994"><span class="cl-87573526">White</span></p></td><td class="cl-875fd8b6"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ad"><p class="cl-875fb994"><span class="cl-87573526">187,064,786</span></p></td><td class="cl-875fd8b6"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ad"><p class="cl-875fb994"><span class="cl-87573526">23,527,256</span></p></td><td class="cl-875fd8b6"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ad"><p class="cl-875fb994"><span class="cl-87573526">148,221,810</span></p></td><td class="cl-875fd8b6"><p class="cl-875fb99e"><span class="cl-8757351c"></span></p></td><td class="cl-875fd8ad"><p class="cl-875fb994"><span class="cl-87573526">13,472,727</span></p></td></tr></tbody></table></div>
</div>
</div>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb56"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb56-1"><a href="#cb56-1" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2022</span></span>
<span id="cb56-2"><a href="#cb56-2" aria-hidden="true" tabindex="-1"></a>t_a1_b <span class="ot">&lt;-</span> d_table_a1 <span class="sc">|&gt;</span></span>
<span id="cb56-3"><a href="#cb56-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election) <span class="sc">|&gt;</span></span>
<span id="cb56-4"><a href="#cb56-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb56-5"><a href="#cb56-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"position"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb56-6"><a href="#cb56-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"rvn_kind"</span>),</span>
<span id="cb56-7"><a href="#cb56-7" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue amount (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb56-8"><a href="#cb56-8" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(rvn_amount, <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb56-9"><a href="#cb56-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb56-10"><a href="#cb56-10" aria-hidden="true" tabindex="-1"></a>t_a1_b <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_a1_b) <span class="sc">|&gt;</span></span>
<span id="cb56-11"><a href="#cb56-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb56-12"><a href="#cb56-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb56-13"><a href="#cb56-13" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb56-14"><a href="#cb56-14" aria-hidden="true" tabindex="-1"></a>      <span class="st">"position"</span> <span class="ot">=</span> <span class="st">"Position"</span>,</span>
<span id="cb56-15"><a href="#cb56-15" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb56-16"><a href="#cb56-16" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb56-17"><a href="#cb56-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb56-18"><a href="#cb56-18" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb56-19"><a href="#cb56-19" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb56-20"><a href="#cb56-20" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb56-21"><a href="#cb56-21" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb56-22"><a href="#cb56-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb56-23"><a href="#cb56-23" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb56-24"><a href="#cb56-24" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb56-25"><a href="#cb56-25" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb56-26"><a href="#cb56-26" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb56-27"><a href="#cb56-27" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb56-28"><a href="#cb56-28" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb56-29"><a href="#cb56-29" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb56-30"><a href="#cb56-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb56-31"><a href="#cb56-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb56-32"><a href="#cb56-32" aria-hidden="true" tabindex="-1"></a>t_a1_b</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-87968dde{}.cl-87905eaa{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-87905ec8{font-family:'Arial';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-87905ec9{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-879354a2{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-879354ac{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-879354ad{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-879354c0{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-879354c1{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-879368a2{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-879368ac{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-879368ad{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0.75pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-879368ae{width:0.8in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-879368b6{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-879368b7{width:0.8in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0.75pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-879368c0{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-879368c1{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-879368ca{width:0.8in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-87968dde"><thead><tr style="overflow-wrap:break-word;"><th rowspan="2" class="cl-879368a2"><p class="cl-879354a2"><span class="cl-87905eaa">Position</span></p></th><th rowspan="2" class="cl-879368a2"><p class="cl-879354a2"><span class="cl-87905eaa">Race/color</span></p></th><th class="cl-879368ac"><p class="cl-879354ac"><span class="cl-87905ec8"></span></p></th><th colspan="3" class="cl-879368ad"><p class="cl-879354ad"><span class="cl-87905eaa">Men</span></p></th><th class="cl-879368ac"><p class="cl-879354ac"><span class="cl-87905ec8"></span></p></th><th colspan="3" class="cl-879368ad"><p class="cl-879354ad"><span class="cl-87905eaa">Women</span></p></th></tr><tr style="overflow-wrap:break-word;"><th class="cl-879368b6"><p class="cl-879354ac"><span class="cl-87905ec8"></span></p></th><th class="cl-879368b7"><p class="cl-879354ad"><span class="cl-87905eaa">Cash</span></p></th><th class="cl-879368b6"><p class="cl-879354ac"><span class="cl-87905ec8"></span></p></th><th class="cl-879368b7"><p class="cl-879354ad"><span class="cl-87905eaa">Cash-equivalent</span></p></th><th class="cl-879368b6"><p class="cl-879354ac"><span class="cl-87905ec8"></span></p></th><th class="cl-879368b7"><p class="cl-879354ad"><span class="cl-87905eaa">Cash</span></p></th><th class="cl-879368b6"><p class="cl-879354ac"><span class="cl-87905ec8"></span></p></th><th class="cl-879368b7"><p class="cl-879354ad"><span class="cl-87905eaa">Cash-equivalent</span></p></th></tr><tr style="overflow-wrap:break-word;"><th colspan="10" class="cl-879368ae"><p class="cl-879354a2"><span class="cl-87905eaa">2022</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">Federal Deputy</span></p></td><td class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">Black</span></p></td><td class="cl-879368c0"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">636,449,463</span></p></td><td class="cl-879368c0"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">18,712,077</span></p></td><td class="cl-879368c0"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">383,379,112</span></p></td><td class="cl-879368c0"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">17,392,251</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">White</span></p></td><td class="cl-879368c0"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">1,204,947,836</span></p></td><td class="cl-879368c0"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">26,559,031</span></p></td><td class="cl-879368c0"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">466,779,311</span></p></td><td class="cl-879368c0"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c0"><p class="cl-879354c0"><span class="cl-87905ec9">13,558,090</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-879368c1"><p class="cl-879354c0"><span class="cl-87905ec9">State Deputy</span></p></td><td class="cl-879368ca"><p class="cl-879354c0"><span class="cl-87905ec9">Black</span></p></td><td class="cl-879368ca"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368ca"><p class="cl-879354c0"><span class="cl-87905ec9">320,473,369</span></p></td><td class="cl-879368ca"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368ca"><p class="cl-879354c0"><span class="cl-87905ec9">33,300,967</span></p></td><td class="cl-879368ca"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368ca"><p class="cl-879354c0"><span class="cl-87905ec9">227,672,524</span></p></td><td class="cl-879368ca"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368ca"><p class="cl-879354c0"><span class="cl-87905ec9">21,590,988</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-879368c1"><p class="cl-879354c0"><span class="cl-87905ec9">White</span></p></td><td class="cl-879368ca"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c1"><p class="cl-879354c0"><span class="cl-87905ec9">425,524,029</span></p></td><td class="cl-879368ca"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c1"><p class="cl-879354c0"><span class="cl-87905ec9">32,718,184</span></p></td><td class="cl-879368ca"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c1"><p class="cl-879354c0"><span class="cl-87905ec9">252,268,259</span></p></td><td class="cl-879368ca"><p class="cl-879354c1"><span class="cl-87905ec8"></span></p></td><td class="cl-879368c1"><p class="cl-879354c0"><span class="cl-87905ec9">19,622,381</span></p></td></tr></tbody></table></div>
</div>
</div>
<p>Save table A-1</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb57"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb57-1"><a href="#cb57-1" aria-hidden="true" tabindex="-1"></a>path <span class="ot">=</span> <span class="st">'..//Tabelas/Paper_Table_A-1_R.docx'</span></span>
<span id="cb57-2"><a href="#cb57-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb57-3"><a href="#cb57-3" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb57-4"><a href="#cb57-4" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_a1_a)</span>
<span id="cb57-5"><a href="#cb57-5" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_a1_b)</span>
<span id="cb57-6"><a href="#cb57-6" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="appendix-b" class="level2">
<h2 class="anchored" data-anchor-id="appendix-b">Appendix B</h2>
<section id="table-b-1---average-public-resource-of-federal-deputies-by-week-of-spending-gender-and-race" class="level3">
<h3 class="anchored" data-anchor-id="table-b-1---average-public-resource-of-federal-deputies-by-week-of-spending-gender-and-race">Table B-1 - Average public resource of federal deputies by week of spending, gender and race</h3>
<p>Create datasets for table B-1 (Federal Deputy)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb58"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb58-1"><a href="#cb58-1" aria-hidden="true" tabindex="-1"></a>d_table_b1 <span class="ot">&lt;-</span> g3_data <span class="sc">%&gt;%</span></span>
<span id="cb58-2"><a href="#cb58-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb58-3"><a href="#cb58-3" aria-hidden="true" tabindex="-1"></a>    <span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb58-4"><a href="#cb58-4" aria-hidden="true" tabindex="-1"></a>    <span class="at">week_revenue =</span> semana_receita,</span>
<span id="cb58-5"><a href="#cb58-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">race_color =</span> cor_raca,</span>
<span id="cb58-6"><a href="#cb58-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">gender =</span> genero,</span>
<span id="cb58-7"><a href="#cb58-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> cargo) <span class="sc">%&gt;%</span></span>
<span id="cb58-8"><a href="#cb58-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(year_election, position, week_revenue, </span>
<span id="cb58-9"><a href="#cb58-9" aria-hidden="true" tabindex="-1"></a>           gender, race_color) <span class="sc">%&gt;%</span></span>
<span id="cb58-10"><a href="#cb58-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">avg_public_revenue =</span> <span class="fu">mean</span>(media_receitas_genero_cor)) <span class="sc">%&gt;%</span></span>
<span id="cb58-11"><a href="#cb58-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">avg_public_revenue =</span> <span class="fu">round</span>(avg_public_revenue, <span class="dv">2</span>))</span>
<span id="cb58-12"><a href="#cb58-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb58-13"><a href="#cb58-13" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(d_table_b1)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":["year_election"],"name":[1],"type":["fct"],"align":["left"]},{"label":["position"],"name":[2],"type":["chr"],"align":["left"]},{"label":["week_revenue"],"name":[3],"type":["date"],"align":["right"]},{"label":["gender"],"name":[4],"type":["chr"],"align":["left"]},{"label":["race_color"],"name":[5],"type":["chr"],"align":["left"]},{"label":["avg_public_revenue"],"name":[6],"type":["dbl"],"align":["right"]}],"data":[{"1":"2018","2":"DEPUTADO FEDERAL","3":"2017-12-31","4":"Men","5":"Black","6":"0.06"},{"1":"2018","2":"DEPUTADO FEDERAL","3":"2018-03-04","4":"Men","5":"Black","6":"0.39"},{"1":"2018","2":"DEPUTADO FEDERAL","3":"2018-05-13","4":"Men","5":"Black","6":"0.30"},{"1":"2018","2":"DEPUTADO FEDERAL","3":"2018-05-20","4":"Women","5":"Black","6":"0.03"},{"1":"2018","2":"DEPUTADO FEDERAL","3":"2018-05-27","4":"Men","5":"Black","6":"0.36"},{"1":"2018","2":"DEPUTADO FEDERAL","3":"2018-07-08","4":"Men","5":"White","6":"0.18"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
</section>
<section id="section" class="level3">
<h3 class="anchored" data-anchor-id="section"></h3>
<p>Plot table B1 - panel “a” (Federal Deputy - 2018)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb59"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb59-1"><a href="#cb59-1" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2018</span></span>
<span id="cb59-2"><a href="#cb59-2" aria-hidden="true" tabindex="-1"></a>min_week_revenue <span class="ot">&lt;-</span> <span class="st">'2018-08-18'</span></span>
<span id="cb59-3"><a href="#cb59-3" aria-hidden="true" tabindex="-1"></a>max_week_revenue <span class="ot">&lt;-</span> <span class="st">'2018-09-30'</span></span>
<span id="cb59-4"><a href="#cb59-4" aria-hidden="true" tabindex="-1"></a>t_b1_a <span class="ot">&lt;-</span> d_table_b1 <span class="sc">|&gt;</span></span>
<span id="cb59-5"><a href="#cb59-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb59-6"><a href="#cb59-6" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&gt;=</span> min_week_revenue,</span>
<span id="cb59-7"><a href="#cb59-7" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&lt;=</span> max_week_revenue) <span class="sc">|&gt;</span></span>
<span id="cb59-8"><a href="#cb59-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb59-9"><a href="#cb59-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"week_revenue"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb59-10"><a href="#cb59-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>),</span>
<span id="cb59-11"><a href="#cb59-11" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb59-12"><a href="#cb59-12" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(avg_public_revenue, <span class="at">formatter =</span> fmt_dbl)))</span>
<span id="cb59-13"><a href="#cb59-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb59-14"><a href="#cb59-14" aria-hidden="true" tabindex="-1"></a>t_b1_a <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_b1_a) <span class="sc">|&gt;</span></span>
<span id="cb59-15"><a href="#cb59-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb59-16"><a href="#cb59-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb59-17"><a href="#cb59-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb59-18"><a href="#cb59-18" aria-hidden="true" tabindex="-1"></a>      <span class="st">"week_revenue"</span> <span class="ot">=</span> <span class="st">"Revenue registration week "</span>,</span>
<span id="cb59-19"><a href="#cb59-19" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb59-20"><a href="#cb59-20" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb59-21"><a href="#cb59-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb59-22"><a href="#cb59-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb59-23"><a href="#cb59-23" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb59-24"><a href="#cb59-24" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">6</span>,</span>
<span id="cb59-25"><a href="#cb59-25" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">TRUE</span>) <span class="sc">|&gt;</span></span>
<span id="cb59-26"><a href="#cb59-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb59-27"><a href="#cb59-27" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.9</span>) <span class="sc">|&gt;</span></span>
<span id="cb59-28"><a href="#cb59-28" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb59-29"><a href="#cb59-29" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb59-30"><a href="#cb59-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb59-31"><a href="#cb59-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb59-32"><a href="#cb59-32" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb59-33"><a href="#cb59-33" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb59-34"><a href="#cb59-34" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb59-35"><a href="#cb59-35" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb59-36"><a href="#cb59-36" aria-hidden="true" tabindex="-1"></a>t_b1_a</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-880d9a0a{}.cl-8808087e{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-88080892{font-family:'Arial';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-88080893{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-880a4490{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-880a449a{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-880a449b{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-880a44a4{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-880a44ae{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-880a5318{width:0.9in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-880a5322{width:0.9in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-880a5323{width:0.9in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-880a532c{width:0.9in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-880a532d{width:0.9in;background-color:transparent;vertical-align: top;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-880d9a0a"><thead><tr style="overflow-wrap:break-word;"><th colspan="6" class="cl-880a5318"><p class="cl-880a4490"><span class="cl-8808087e">2018</span></p></th></tr><tr style="overflow-wrap:break-word;"><th class="cl-880a5318"><p class="cl-880a4490"><span class="cl-8808087e">Revenue registration week </span></p></th><th class="cl-880a5318"><p class="cl-880a4490"><span class="cl-8808087e">Race/color</span></p></th><th class="cl-880a5322"><p class="cl-880a449a"><span class="cl-88080892"></span></p></th><th class="cl-880a5323"><p class="cl-880a449b"><span class="cl-8808087e">Men</span></p></th><th class="cl-880a5322"><p class="cl-880a449a"><span class="cl-88080892"></span></p></th><th class="cl-880a5323"><p class="cl-880a449b"><span class="cl-8808087e">Women</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">2018-08-19</span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">Black</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">29,557.02</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">21,275.77</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">White</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">94,518.82</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">43,134.52</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">2018-08-26</span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">Black</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">42,982.24</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">14,988.68</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">White</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">84,573.12</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">35,509.92</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">2018-09-02</span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">Black</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">12,044.77</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">9,165.29</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">White</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">23,462.64</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">19,643.35</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">2018-09-09</span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">Black</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">14,523.81</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">11,915.08</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">White</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">29,632.70</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">28,962.01</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">2018-09-16</span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">Black</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">9,737.36</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">12,572.44</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">White</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">19,868.56</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">17,607.31</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">2018-09-23</span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">Black</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">7,466.26</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">7,366.07</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">White</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">15,101.70</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">14,709.13</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-880a532d"><p class="cl-880a44a4"><span class="cl-88080893">2018-09-30</span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">Black</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">4,900.34</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532c"><p class="cl-880a44a4"><span class="cl-88080893">7,496.11</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-880a532d"><p class="cl-880a44a4"><span class="cl-88080893">White</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532d"><p class="cl-880a44a4"><span class="cl-88080893">8,885.93</span></p></td><td class="cl-880a532c"><p class="cl-880a44ae"><span class="cl-88080892"></span></p></td><td class="cl-880a532d"><p class="cl-880a44a4"><span class="cl-88080893">13,779.95</span></p></td></tr></tbody></table></div>
</div>
</div>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb60"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb60-1"><a href="#cb60-1" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2022</span></span>
<span id="cb60-2"><a href="#cb60-2" aria-hidden="true" tabindex="-1"></a>min_week_revenue <span class="ot">&lt;-</span> <span class="st">'2022-08-21'</span></span>
<span id="cb60-3"><a href="#cb60-3" aria-hidden="true" tabindex="-1"></a>max_week_revenue <span class="ot">&lt;-</span> <span class="st">'2022-09-25'</span></span>
<span id="cb60-4"><a href="#cb60-4" aria-hidden="true" tabindex="-1"></a>t_b1_b <span class="ot">&lt;-</span> d_table_b1 <span class="sc">|&gt;</span></span>
<span id="cb60-5"><a href="#cb60-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb60-6"><a href="#cb60-6" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&gt;=</span> min_week_revenue,</span>
<span id="cb60-7"><a href="#cb60-7" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&lt;=</span> max_week_revenue) <span class="sc">|&gt;</span></span>
<span id="cb60-8"><a href="#cb60-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb60-9"><a href="#cb60-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"week_revenue"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb60-10"><a href="#cb60-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>),</span>
<span id="cb60-11"><a href="#cb60-11" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb60-12"><a href="#cb60-12" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(avg_public_revenue, <span class="at">formatter =</span> fmt_dbl)))</span>
<span id="cb60-13"><a href="#cb60-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb60-14"><a href="#cb60-14" aria-hidden="true" tabindex="-1"></a>t_b1_b <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_b1_b) <span class="sc">|&gt;</span></span>
<span id="cb60-15"><a href="#cb60-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb60-16"><a href="#cb60-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb60-17"><a href="#cb60-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb60-18"><a href="#cb60-18" aria-hidden="true" tabindex="-1"></a>      <span class="st">"week_revenue"</span> <span class="ot">=</span> <span class="st">"Revenue registration week "</span>,</span>
<span id="cb60-19"><a href="#cb60-19" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb60-20"><a href="#cb60-20" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb60-21"><a href="#cb60-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb60-22"><a href="#cb60-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb60-23"><a href="#cb60-23" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb60-24"><a href="#cb60-24" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">6</span>,</span>
<span id="cb60-25"><a href="#cb60-25" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">TRUE</span>) <span class="sc">|&gt;</span></span>
<span id="cb60-26"><a href="#cb60-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb60-27"><a href="#cb60-27" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.9</span>) <span class="sc">|&gt;</span></span>
<span id="cb60-28"><a href="#cb60-28" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb60-29"><a href="#cb60-29" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb60-30"><a href="#cb60-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb60-31"><a href="#cb60-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb60-32"><a href="#cb60-32" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb60-33"><a href="#cb60-33" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb60-34"><a href="#cb60-34" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb60-35"><a href="#cb60-35" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb60-36"><a href="#cb60-36" aria-hidden="true" tabindex="-1"></a>t_b1_b</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-8830f2f2{}.cl-882afdac{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-882afdb6{font-family:'Arial';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-882afdc0{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-882d3efa{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-882d3f04{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-882d3f0e{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-882d3f0f{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-882d3f10{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-882d4f12{width:0.9in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-882d4f1c{width:0.9in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-882d4f1d{width:0.9in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-882d4f1e{width:0.9in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-882d4f1f{width:0.9in;background-color:transparent;vertical-align: top;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-8830f2f2"><thead><tr style="overflow-wrap:break-word;"><th colspan="6" class="cl-882d4f12"><p class="cl-882d3efa"><span class="cl-882afdac">2022</span></p></th></tr><tr style="overflow-wrap:break-word;"><th class="cl-882d4f12"><p class="cl-882d3efa"><span class="cl-882afdac">Revenue registration week </span></p></th><th class="cl-882d4f12"><p class="cl-882d3efa"><span class="cl-882afdac">Race/color</span></p></th><th class="cl-882d4f1c"><p class="cl-882d3f04"><span class="cl-882afdb6"></span></p></th><th class="cl-882d4f1d"><p class="cl-882d3f0e"><span class="cl-882afdac">Men</span></p></th><th class="cl-882d4f1c"><p class="cl-882d3f04"><span class="cl-882afdb6"></span></p></th><th class="cl-882d4f1d"><p class="cl-882d3f0e"><span class="cl-882afdac">Women</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">2022-08-21</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">Black</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">89,009.92</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">61,033.96</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">White</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">151,963.31</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">101,341.72</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">2022-08-28</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">Black</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">59,480.42</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">59,943.50</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">White</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">91,085.74</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">79,938.27</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">2022-09-04</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">Black</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">33,851.48</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">46,429.50</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">White</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">40,682.54</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">38,957.66</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">2022-09-11</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">Black</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">37,677.49</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">41,349.96</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">White</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">60,499.50</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">54,926.28</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">2022-09-18</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">Black</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">13,685.15</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">11,713.47</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">White</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">25,928.18</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">19,734.34</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-882d4f1f"><p class="cl-882d3f0f"><span class="cl-882afdc0">2022-09-25</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">Black</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">8,382.82</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f0f"><span class="cl-882afdc0">10,783.08</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-882d4f1f"><p class="cl-882d3f0f"><span class="cl-882afdc0">White</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1f"><p class="cl-882d3f0f"><span class="cl-882afdc0">10,321.96</span></p></td><td class="cl-882d4f1e"><p class="cl-882d3f10"><span class="cl-882afdb6"></span></p></td><td class="cl-882d4f1f"><p class="cl-882d3f0f"><span class="cl-882afdc0">9,134.66</span></p></td></tr></tbody></table></div>
</div>
</div>
<p>Save table B-1</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb61"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb61-1"><a href="#cb61-1" aria-hidden="true" tabindex="-1"></a>path <span class="ot">=</span> <span class="st">'..//Tabelas/Paper_Table_B-1_R.docx'</span></span>
<span id="cb61-2"><a href="#cb61-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb61-3"><a href="#cb61-3" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb61-4"><a href="#cb61-4" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_b1_a)</span>
<span id="cb61-5"><a href="#cb61-5" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_b1_b)</span>
<span id="cb61-6"><a href="#cb61-6" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="table-b-2---average-public-resource-of-state-deputy-by-revenue-registration-week-gender-and-race" class="level3">
<h3 class="anchored" data-anchor-id="table-b-2---average-public-resource-of-state-deputy-by-revenue-registration-week-gender-and-race">Table B-2 - Average public resource of state deputy by revenue registration week, gender and race</h3>
<p>Create datasets for table B-2 (State Deputy)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb62"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb62-1"><a href="#cb62-1" aria-hidden="true" tabindex="-1"></a>d_table_b2 <span class="ot">&lt;-</span> g4_data <span class="sc">%&gt;%</span></span>
<span id="cb62-2"><a href="#cb62-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb62-3"><a href="#cb62-3" aria-hidden="true" tabindex="-1"></a>    <span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb62-4"><a href="#cb62-4" aria-hidden="true" tabindex="-1"></a>    <span class="at">week_revenue =</span> semana_receita,</span>
<span id="cb62-5"><a href="#cb62-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">race_color =</span> cor_raca,</span>
<span id="cb62-6"><a href="#cb62-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">gender =</span> genero,</span>
<span id="cb62-7"><a href="#cb62-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">ifelse</span>(</span>
<span id="cb62-8"><a href="#cb62-8" aria-hidden="true" tabindex="-1"></a>      cargo <span class="sc">==</span> <span class="st">"DEPUTADO DISTRITAL"</span> <span class="sc">|</span> cargo <span class="sc">==</span> <span class="st">"DEPUTADO ESTADUAL"</span>, </span>
<span id="cb62-9"><a href="#cb62-9" aria-hidden="true" tabindex="-1"></a>      <span class="st">"State Deputy"</span>, </span>
<span id="cb62-10"><a href="#cb62-10" aria-hidden="true" tabindex="-1"></a>      cargo)) <span class="sc">%&gt;%</span></span>
<span id="cb62-11"><a href="#cb62-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(year_election, position, week_revenue, </span>
<span id="cb62-12"><a href="#cb62-12" aria-hidden="true" tabindex="-1"></a>           gender, race_color) <span class="sc">%&gt;%</span></span>
<span id="cb62-13"><a href="#cb62-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">avg_public_revenue =</span> <span class="fu">mean</span>(media_receitas_genero_cor)) <span class="sc">%&gt;%</span></span>
<span id="cb62-14"><a href="#cb62-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">avg_public_revenue =</span> <span class="fu">round</span>(avg_public_revenue, <span class="dv">2</span>))</span>
<span id="cb62-15"><a href="#cb62-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb62-16"><a href="#cb62-16" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(d_table_b2)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":["year_election"],"name":[1],"type":["fct"],"align":["left"]},{"label":["position"],"name":[2],"type":["chr"],"align":["left"]},{"label":["week_revenue"],"name":[3],"type":["date"],"align":["right"]},{"label":["gender"],"name":[4],"type":["chr"],"align":["left"]},{"label":["race_color"],"name":[5],"type":["chr"],"align":["left"]},{"label":["avg_public_revenue"],"name":[6],"type":["dbl"],"align":["right"]}],"data":[{"1":"2018","2":"State Deputy","3":"2018-01-21","4":"Women","5":"White","6":"0.36"},{"1":"2018","2":"State Deputy","3":"2018-03-25","4":"Men","5":"White","6":"0.22"},{"1":"2018","2":"State Deputy","3":"2018-05-27","4":"Men","5":"White","6":"0.02"},{"1":"2018","2":"State Deputy","3":"2018-06-03","4":"Men","5":"White","6":"0.27"},{"1":"2018","2":"State Deputy","3":"2018-06-03","4":"Women","5":"White","6":"0.29"},{"1":"2018","2":"State Deputy","3":"2018-07-22","4":"Men","5":"Black","6":"3.94"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
<p>Plot table B2 - panel “a” (State Deputy - 2018)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb63"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb63-1"><a href="#cb63-1" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2018</span></span>
<span id="cb63-2"><a href="#cb63-2" aria-hidden="true" tabindex="-1"></a>min_week_revenue <span class="ot">&lt;-</span> <span class="st">'2018-08-18'</span></span>
<span id="cb63-3"><a href="#cb63-3" aria-hidden="true" tabindex="-1"></a>max_week_revenue <span class="ot">&lt;-</span> <span class="st">'2018-09-30'</span></span>
<span id="cb63-4"><a href="#cb63-4" aria-hidden="true" tabindex="-1"></a>t_b2_a <span class="ot">&lt;-</span> d_table_b2 <span class="sc">|&gt;</span></span>
<span id="cb63-5"><a href="#cb63-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb63-6"><a href="#cb63-6" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&gt;=</span> min_week_revenue,</span>
<span id="cb63-7"><a href="#cb63-7" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&lt;=</span> max_week_revenue) <span class="sc">|&gt;</span></span>
<span id="cb63-8"><a href="#cb63-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb63-9"><a href="#cb63-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"week_revenue"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb63-10"><a href="#cb63-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>),</span>
<span id="cb63-11"><a href="#cb63-11" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb63-12"><a href="#cb63-12" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(avg_public_revenue, <span class="at">formatter =</span> fmt_dbl)))</span>
<span id="cb63-13"><a href="#cb63-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb63-14"><a href="#cb63-14" aria-hidden="true" tabindex="-1"></a>t_b2_a <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_b2_a) <span class="sc">|&gt;</span></span>
<span id="cb63-15"><a href="#cb63-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb63-16"><a href="#cb63-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb63-17"><a href="#cb63-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb63-18"><a href="#cb63-18" aria-hidden="true" tabindex="-1"></a>      <span class="st">"week_revenue"</span> <span class="ot">=</span> <span class="st">"Revenue registration week"</span>,</span>
<span id="cb63-19"><a href="#cb63-19" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb63-20"><a href="#cb63-20" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb63-21"><a href="#cb63-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb63-22"><a href="#cb63-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb63-23"><a href="#cb63-23" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb63-24"><a href="#cb63-24" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">6</span>,</span>
<span id="cb63-25"><a href="#cb63-25" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">TRUE</span>) <span class="sc">|&gt;</span></span>
<span id="cb63-26"><a href="#cb63-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb63-27"><a href="#cb63-27" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.9</span>) <span class="sc">|&gt;</span></span>
<span id="cb63-28"><a href="#cb63-28" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb63-29"><a href="#cb63-29" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb63-30"><a href="#cb63-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb63-31"><a href="#cb63-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb63-32"><a href="#cb63-32" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb63-33"><a href="#cb63-33" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb63-34"><a href="#cb63-34" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb63-35"><a href="#cb63-35" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb63-36"><a href="#cb63-36" aria-hidden="true" tabindex="-1"></a>t_b2_a</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-88b50402{}.cl-88ae5f62{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-88ae5f6c{font-family:'Arial';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-88ae5f76{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-88b0ee12{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-88b0ee1c{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-88b0ee26{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-88b0ee3a{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-88b0ee3b{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-88b113a6{width:0.9in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-88b113b0{width:0.9in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-88b113b1{width:0.9in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-88b113ba{width:0.9in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-88b113c4{width:0.9in;background-color:transparent;vertical-align: top;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-88b50402"><thead><tr style="overflow-wrap:break-word;"><th colspan="6" class="cl-88b113a6"><p class="cl-88b0ee12"><span class="cl-88ae5f62">2018</span></p></th></tr><tr style="overflow-wrap:break-word;"><th class="cl-88b113a6"><p class="cl-88b0ee12"><span class="cl-88ae5f62">Revenue registration week</span></p></th><th class="cl-88b113a6"><p class="cl-88b0ee12"><span class="cl-88ae5f62">Race/color</span></p></th><th class="cl-88b113b0"><p class="cl-88b0ee1c"><span class="cl-88ae5f6c"></span></p></th><th class="cl-88b113b1"><p class="cl-88b0ee26"><span class="cl-88ae5f62">Men</span></p></th><th class="cl-88b113b0"><p class="cl-88b0ee1c"><span class="cl-88ae5f6c"></span></p></th><th class="cl-88b113b1"><p class="cl-88b0ee26"><span class="cl-88ae5f62">Women</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">2018-08-19</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">Black</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">2,118.20</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">2,515.11</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">White</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">6,084.38</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">6,673.10</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">2018-08-26</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">Black</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">6,769.60</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">10,614.63</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">White</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">13,664.74</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">17,762.36</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">2018-09-02</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">Black</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">3,401.62</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">7,083.65</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">White</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">7,956.86</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">12,110.92</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">2018-09-09</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">Black</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">4,269.91</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">7,598.28</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">White</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">8,428.90</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">13,692.05</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">2018-09-16</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">Black</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">3,104.10</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">5,876.35</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">White</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">6,287.20</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">9,394.71</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">2018-09-23</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">Black</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">3,160.64</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">5,865.17</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">White</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">5,827.58</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">8,679.22</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88b113c4"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">2018-09-30</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">Black</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">3,918.62</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">5,263.32</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88b113c4"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">White</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113c4"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">4,747.98</span></p></td><td class="cl-88b113ba"><p class="cl-88b0ee3b"><span class="cl-88ae5f6c"></span></p></td><td class="cl-88b113c4"><p class="cl-88b0ee3a"><span class="cl-88ae5f76">8,345.33</span></p></td></tr></tbody></table></div>
</div>
</div>
<p>Plot table B2 - panel “b” (State Deputy - 2022)</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb64"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb64-1"><a href="#cb64-1" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2022</span></span>
<span id="cb64-2"><a href="#cb64-2" aria-hidden="true" tabindex="-1"></a>min_week_revenue <span class="ot">&lt;-</span> <span class="st">'2022-08-21'</span></span>
<span id="cb64-3"><a href="#cb64-3" aria-hidden="true" tabindex="-1"></a>max_week_revenue <span class="ot">&lt;-</span> <span class="st">'2022-09-25'</span></span>
<span id="cb64-4"><a href="#cb64-4" aria-hidden="true" tabindex="-1"></a>t_b2_b <span class="ot">&lt;-</span> d_table_b2 <span class="sc">|&gt;</span></span>
<span id="cb64-5"><a href="#cb64-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb64-6"><a href="#cb64-6" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&gt;=</span> min_week_revenue,</span>
<span id="cb64-7"><a href="#cb64-7" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&lt;=</span> max_week_revenue) <span class="sc">|&gt;</span></span>
<span id="cb64-8"><a href="#cb64-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb64-9"><a href="#cb64-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"week_revenue"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb64-10"><a href="#cb64-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>),</span>
<span id="cb64-11"><a href="#cb64-11" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb64-12"><a href="#cb64-12" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(avg_public_revenue, <span class="at">formatter =</span> fmt_dbl)))</span>
<span id="cb64-13"><a href="#cb64-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb64-14"><a href="#cb64-14" aria-hidden="true" tabindex="-1"></a>t_b2_b <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_b2_b) <span class="sc">|&gt;</span></span>
<span id="cb64-15"><a href="#cb64-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb64-16"><a href="#cb64-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb64-17"><a href="#cb64-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb64-18"><a href="#cb64-18" aria-hidden="true" tabindex="-1"></a>      <span class="st">"week_revenue"</span> <span class="ot">=</span> <span class="st">"Revenue registration week "</span>,</span>
<span id="cb64-19"><a href="#cb64-19" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb64-20"><a href="#cb64-20" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb64-21"><a href="#cb64-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb64-22"><a href="#cb64-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb64-23"><a href="#cb64-23" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb64-24"><a href="#cb64-24" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">6</span>,</span>
<span id="cb64-25"><a href="#cb64-25" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">TRUE</span>) <span class="sc">|&gt;</span></span>
<span id="cb64-26"><a href="#cb64-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb64-27"><a href="#cb64-27" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.9</span>) <span class="sc">|&gt;</span></span>
<span id="cb64-28"><a href="#cb64-28" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb64-29"><a href="#cb64-29" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb64-30"><a href="#cb64-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb64-31"><a href="#cb64-31" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb64-32"><a href="#cb64-32" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb64-33"><a href="#cb64-33" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb64-34"><a href="#cb64-34" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb64-35"><a href="#cb64-35" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb64-36"><a href="#cb64-36" aria-hidden="true" tabindex="-1"></a>t_b2_b</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
<div class="cell-output-display">

<div class="tabwid"><style>.cl-88dcca1e{}.cl-88d675b0{font-family:'Times New Roman';font-size:10pt;font-weight:bold;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-88d675ba{font-family:'Arial';font-size:11pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-88d675c4{font-family:'Times New Roman';font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:rgba(0, 0, 0, 1.00);background-color:transparent;}.cl-88d8e7be{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-88d8e7c8{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-88d8e7d2{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-88d8e7d3{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:5pt;padding-top:5pt;padding-left:5pt;padding-right:5pt;line-height: 1;background-color:transparent;}.cl-88d8e7dc{margin:0;text-align:center;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);padding-bottom:0;padding-top:0;padding-left:0;padding-right:0;line-height: 1;background-color:transparent;}.cl-88d8f9e8{width:0.9in;background-color:transparent;vertical-align: bottom;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-88d8f9e9{width:0.9in;background-color:transparent;vertical-align: middle;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-88d8f9fc{width:0.9in;background-color:transparent;vertical-align: middle;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 1.5pt solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-88d8fa1a{width:0.9in;background-color:transparent;vertical-align: top;border-bottom: 0 solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}.cl-88d8fa1b{width:0.9in;background-color:transparent;vertical-align: top;border-bottom: 1.5pt solid rgba(0, 0, 0, 1.00);border-top: 0 solid rgba(0, 0, 0, 1.00);border-left: 0 solid rgba(0, 0, 0, 1.00);border-right: 0 solid rgba(0, 0, 0, 1.00);margin-bottom:0;margin-top:0;margin-left:0;margin-right:0;}</style><table data-quarto-disable-processing="true" class="cl-88dcca1e"><thead><tr style="overflow-wrap:break-word;"><th colspan="6" class="cl-88d8f9e8"><p class="cl-88d8e7be"><span class="cl-88d675b0">2022</span></p></th></tr><tr style="overflow-wrap:break-word;"><th class="cl-88d8f9e8"><p class="cl-88d8e7be"><span class="cl-88d675b0">Revenue registration week </span></p></th><th class="cl-88d8f9e8"><p class="cl-88d8e7be"><span class="cl-88d675b0">Race/color</span></p></th><th class="cl-88d8f9e9"><p class="cl-88d8e7c8"><span class="cl-88d675ba"></span></p></th><th class="cl-88d8f9fc"><p class="cl-88d8e7d2"><span class="cl-88d675b0">Men</span></p></th><th class="cl-88d8f9e9"><p class="cl-88d8e7c8"><span class="cl-88d675ba"></span></p></th><th class="cl-88d8f9fc"><p class="cl-88d8e7d2"><span class="cl-88d675b0">Women</span></p></th></tr></thead><tbody><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">2022-08-21</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">Black</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">18,014.35</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">18,815.77</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">White</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">27,935.38</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">30,512.15</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">2022-08-28</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">Black</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">18,711.36</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">24,050.54</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">White</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">28,158.43</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">38,946.96</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">2022-09-04</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">Black</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">14,595.53</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">17,661.90</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">White</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">14,652.66</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">18,263.83</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">2022-09-11</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">Black</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">16,826.21</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">20,633.66</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">White</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">22,769.49</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">24,510.59</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">2022-09-18</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">Black</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">8,773.08</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">6,777.34</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">White</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">10,971.61</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">9,215.85</span></p></td></tr><tr style="overflow-wrap:break-word;"><td rowspan="2" class="cl-88d8fa1b"><p class="cl-88d8e7d3"><span class="cl-88d675c4">2022-09-25</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">Black</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">5,103.25</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7d3"><span class="cl-88d675c4">6,013.29</span></p></td></tr><tr style="overflow-wrap:break-word;"><td class="cl-88d8fa1b"><p class="cl-88d8e7d3"><span class="cl-88d675c4">White</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1b"><p class="cl-88d8e7d3"><span class="cl-88d675c4">6,876.36</span></p></td><td class="cl-88d8fa1a"><p class="cl-88d8e7dc"><span class="cl-88d675ba"></span></p></td><td class="cl-88d8fa1b"><p class="cl-88d8e7d3"><span class="cl-88d675c4">6,506.09</span></p></td></tr></tbody></table></div>
</div>
</div>
<p>Save table B-2</p>
<div class="cell">
<details>
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb65"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb65-1"><a href="#cb65-1" aria-hidden="true" tabindex="-1"></a>path <span class="ot">=</span> <span class="st">'..//Tabelas/Paper_Table_B-2_R.docx'</span></span>
<span id="cb65-2"><a href="#cb65-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb65-3"><a href="#cb65-3" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb65-4"><a href="#cb65-4" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_b2_a)</span>
<span id="cb65-5"><a href="#cb65-5" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_b2_b)</span>
<span id="cb65-6"><a href="#cb65-6" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
</section>
<section id="section-1" class="level3">
<h3 class="anchored" data-anchor-id="section-1"></h3>
<!-- -->

</section>
</section>
</section>

</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
  const toggleBodyColorMode = (bsSheetEl) => {
    const mode = bsSheetEl.getAttribute("data-mode");
    const bodyEl = window.document.querySelector("body");
    if (mode === "dark") {
      bodyEl.classList.add("quarto-dark");
      bodyEl.classList.remove("quarto-light");
    } else {
      bodyEl.classList.add("quarto-light");
      bodyEl.classList.remove("quarto-dark");
    }
  }
  const toggleBodyColorPrimary = () => {
    const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
    if (bsSheetEl) {
      toggleBodyColorMode(bsSheetEl);
    }
  }
  toggleBodyColorPrimary();  
  const icon = "";
  const anchorJS = new window.AnchorJS();
  anchorJS.options = {
    placement: 'right',
    icon: icon
  };
  anchorJS.add('.anchored');
  const isCodeAnnotation = (el) => {
    for (const clz of el.classList) {
      if (clz.startsWith('code-annotation-')) {                     
        return true;
      }
    }
    return false;
  }
  const clipboard = new window.ClipboardJS('.code-copy-button', {
    text: function(trigger) {
      const codeEl = trigger.previousElementSibling.cloneNode(true);
      for (const childEl of codeEl.children) {
        if (isCodeAnnotation(childEl)) {
          childEl.remove();
        }
      }
      return codeEl.innerText;
    }
  });
  clipboard.on('success', function(e) {
    // button target
    const button = e.trigger;
    // don't keep focus
    button.blur();
    // flash "checked"
    button.classList.add('code-copy-button-checked');
    var currentTitle = button.getAttribute("title");
    button.setAttribute("title", "Copied!");
    let tooltip;
    if (window.bootstrap) {
      button.setAttribute("data-bs-toggle", "tooltip");
      button.setAttribute("data-bs-placement", "left");
      button.setAttribute("data-bs-title", "Copied!");
      tooltip = new bootstrap.Tooltip(button, 
        { trigger: "manual", 
          customClass: "code-copy-button-tooltip",
          offset: [0, -8]});
      tooltip.show();    
    }
    setTimeout(function() {
      if (tooltip) {
        tooltip.hide();
        button.removeAttribute("data-bs-title");
        button.removeAttribute("data-bs-toggle");
        button.removeAttribute("data-bs-placement");
      }
      button.setAttribute("title", currentTitle);
      button.classList.remove('code-copy-button-checked');
    }, 1000);
    // clear code selection
    e.clearSelection();
  });
  const viewSource = window.document.getElementById('quarto-view-source') ||
                     window.document.getElementById('quarto-code-tools-source');
  if (viewSource) {
    const sourceUrl = viewSource.getAttribute("data-quarto-source-url");
    viewSource.addEventListener("click", function(e) {
      if (sourceUrl) {
        // rstudio viewer pane
        if (/\bcapabilities=\b/.test(window.location)) {
          window.open(sourceUrl);
        } else {
          window.location.href = sourceUrl;
        }
      } else {
        const modal = new bootstrap.Modal(document.getElementById('quarto-embedded-source-code-modal'));
        modal.show();
      }
      return false;
    });
  }
  function toggleCodeHandler(show) {
    return function(e) {
      const detailsSrc = window.document.querySelectorAll(".cell > details > .sourceCode");
      for (let i=0; i<detailsSrc.length; i++) {
        const details = detailsSrc[i].parentElement;
        if (show) {
          details.open = true;
        } else {
          details.removeAttribute("open");
        }
      }
      const cellCodeDivs = window.document.querySelectorAll(".cell > .sourceCode");
      const fromCls = show ? "hidden" : "unhidden";
      const toCls = show ? "unhidden" : "hidden";
      for (let i=0; i<cellCodeDivs.length; i++) {
        const codeDiv = cellCodeDivs[i];
        if (codeDiv.classList.contains(fromCls)) {
          codeDiv.classList.remove(fromCls);
          codeDiv.classList.add(toCls);
        } 
      }
      return false;
    }
  }
  const hideAllCode = window.document.getElementById("quarto-hide-all-code");
  if (hideAllCode) {
    hideAllCode.addEventListener("click", toggleCodeHandler(false));
  }
  const showAllCode = window.document.getElementById("quarto-show-all-code");
  if (showAllCode) {
    showAllCode.addEventListener("click", toggleCodeHandler(true));
  }
  function tippyHover(el, contentFn) {
    const config = {
      allowHTML: true,
      content: contentFn,
      maxWidth: 500,
      delay: 100,
      arrow: false,
      appendTo: function(el) {
          return el.parentElement;
      },
      interactive: true,
      interactiveBorder: 10,
      theme: 'quarto',
      placement: 'bottom-start'
    };
    window.tippy(el, config); 
  }
  const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
  for (var i=0; i<noterefs.length; i++) {
    const ref = noterefs[i];
    tippyHover(ref, function() {
      // use id or data attribute instead here
      let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
      try { href = new URL(href).hash; } catch {}
      const id = href.replace(/^#\/?/, "");
      const note = window.document.getElementById(id);
      return note.innerHTML;
    });
  }
      let selectedAnnoteEl;
      const selectorForAnnotation = ( cell, annotation) => {
        let cellAttr = 'data-code-cell="' + cell + '"';
        let lineAttr = 'data-code-annotation="' +  annotation + '"';
        const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
        return selector;
      }
      const selectCodeLines = (annoteEl) => {
        const doc = window.document;
        const targetCell = annoteEl.getAttribute("data-target-cell");
        const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
        const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
        const lines = annoteSpan.getAttribute("data-code-lines").split(",");
        const lineIds = lines.map((line) => {
          return targetCell + "-" + line;
        })
        let top = null;
        let height = null;
        let parent = null;
        if (lineIds.length > 0) {
            //compute the position of the single el (top and bottom and make a div)
            const el = window.document.getElementById(lineIds[0]);
            top = el.offsetTop;
            height = el.offsetHeight;
            parent = el.parentElement.parentElement;
          if (lineIds.length > 1) {
            const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
            const bottom = lastEl.offsetTop + lastEl.offsetHeight;
            height = bottom - top;
          }
          if (top !== null && height !== null && parent !== null) {
            // cook up a div (if necessary) and position it 
            let div = window.document.getElementById("code-annotation-line-highlight");
            if (div === null) {
              div = window.document.createElement("div");
              div.setAttribute("id", "code-annotation-line-highlight");
              div.style.position = 'absolute';
              parent.appendChild(div);
            }
            div.style.top = top - 2 + "px";
            div.style.height = height + 4 + "px";
            let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
            if (gutterDiv === null) {
              gutterDiv = window.document.createElement("div");
              gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
              gutterDiv.style.position = 'absolute';
              const codeCell = window.document.getElementById(targetCell);
              const gutter = codeCell.querySelector('.code-annotation-gutter');
              gutter.appendChild(gutterDiv);
            }
            gutterDiv.style.top = top - 2 + "px";
            gutterDiv.style.height = height + 4 + "px";
          }
          selectedAnnoteEl = annoteEl;
        }
      };
      const unselectCodeLines = () => {
        const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
        elementsIds.forEach((elId) => {
          const div = window.document.getElementById(elId);
          if (div) {
            div.remove();
          }
        });
        selectedAnnoteEl = undefined;
      };
      // Attach click handler to the DT
      const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
      for (const annoteDlNode of annoteDls) {
        annoteDlNode.addEventListener('click', (event) => {
          const clickedEl = event.target;
          if (clickedEl !== selectedAnnoteEl) {
            unselectCodeLines();
            const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
            if (activeEl) {
              activeEl.classList.remove('code-annotation-active');
            }
            selectCodeLines(clickedEl);
            clickedEl.classList.add('code-annotation-active');
          } else {
            // Unselect the line
            unselectCodeLines();
            clickedEl.classList.remove('code-annotation-active');
          }
        });
      }
  const findCites = (el) => {
    const parentEl = el.parentElement;
    if (parentEl) {
      const cites = parentEl.dataset.cites;
      if (cites) {
        return {
          el,
          cites: cites.split(' ')
        };
      } else {
        return findCites(el.parentElement)
      }
    } else {
      return undefined;
    }
  };
  var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
  for (var i=0; i<bibliorefs.length; i++) {
    const ref = bibliorefs[i];
    const citeInfo = findCites(ref);
    if (citeInfo) {
      tippyHover(citeInfo.el, function() {
        var popup = window.document.createElement('div');
        citeInfo.cites.forEach(function(cite) {
          var citeDiv = window.document.createElement('div');
          citeDiv.classList.add('hanging-indent');
          citeDiv.classList.add('csl-entry');
          var biblioDiv = window.document.getElementById('ref-' + cite);
          if (biblioDiv) {
            citeDiv.innerHTML = biblioDiv.innerHTML;
          }
          popup.appendChild(citeDiv);
        });
        return popup.innerHTML;
      });
    }
  }
    var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
      var filterRegex = new RegExp('/' + window.location.host + '/');
    var isInternal = (href) => {
        return filterRegex.test(href) || localhostRegex.test(href);
    }
    // Inspect non-navigation links and adorn them if external
 	var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item)');
    for (var i=0; i<links.length; i++) {
      const link = links[i];
      if (!isInternal(link.href)) {
          // default icon
          link.classList.add("external");
      }
    }
});
</script><div class="modal fade" id="quarto-embedded-source-code-modal" tabindex="-1" aria-labelledby="quarto-embedded-source-code-modal-label" aria-hidden="true"><div class="modal-dialog modal-dialog-scrollable"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="quarto-embedded-source-code-modal-label">Source Code</h5><button class="btn-close" data-bs-dismiss="modal"></button></div><div class="modal-body"><div class="">
<div class="sourceCode" id="cb66" data-shortcodes="false"><pre class="sourceCode markdown code-with-copy"><code class="sourceCode markdown"><span id="cb66-1"><a href="#cb66-1" aria-hidden="true" tabindex="-1"></a><span class="co">---</span></span>
<span id="cb66-2"><a href="#cb66-2" aria-hidden="true" tabindex="-1"></a><span class="an">title-block-banner:</span><span class="co"> true</span></span>
<span id="cb66-3"><a href="#cb66-3" aria-hidden="true" tabindex="-1"></a><span class="an">title:</span><span class="co"> "Paper RBCP 2025"</span></span>
<span id="cb66-4"><a href="#cb66-4" aria-hidden="true" tabindex="-1"></a><span class="an">lang:</span><span class="co"> en</span></span>
<span id="cb66-5"><a href="#cb66-5" aria-hidden="true" tabindex="-1"></a><span class="an">author:</span><span class="co"> </span></span>
<span id="cb66-6"><a href="#cb66-6" aria-hidden="true" tabindex="-1"></a><span class="co">  - id: ts</span></span>
<span id="cb66-7"><a href="#cb66-7" aria-hidden="true" tabindex="-1"></a><span class="co">    name: Teresa Sacchet</span></span>
<span id="cb66-8"><a href="#cb66-8" aria-hidden="true" tabindex="-1"></a><span class="co">    degrees: PhD</span></span>
<span id="cb66-9"><a href="#cb66-9" aria-hidden="true" tabindex="-1"></a><span class="co">    email: teresa.sacchet@gmail.com</span></span>
<span id="cb66-10"><a href="#cb66-10" aria-hidden="true" tabindex="-1"></a><span class="co">    orcid: 0000-0002-1592-2169</span></span>
<span id="cb66-11"><a href="#cb66-11" aria-hidden="true" tabindex="-1"></a><span class="co">    affiliations:</span></span>
<span id="cb66-12"><a href="#cb66-12" aria-hidden="true" tabindex="-1"></a><span class="co">      - ref: ufrgs</span></span>
<span id="cb66-13"><a href="#cb66-13" aria-hidden="true" tabindex="-1"></a><span class="co">  - id: hma</span></span>
<span id="cb66-14"><a href="#cb66-14" aria-hidden="true" tabindex="-1"></a><span class="co">    name: Hannah Maruci Aflalo</span></span>
<span id="cb66-15"><a href="#cb66-15" aria-hidden="true" tabindex="-1"></a><span class="co">    email: hannahmaruci@gmail.com</span></span>
<span id="cb66-16"><a href="#cb66-16" aria-hidden="true" tabindex="-1"></a><span class="co">    orcid: 0000-0002-4820-2942</span></span>
<span id="cb66-17"><a href="#cb66-17" aria-hidden="true" tabindex="-1"></a><span class="co">    degrees: PhD</span></span>
<span id="cb66-18"><a href="#cb66-18" aria-hidden="true" tabindex="-1"></a><span class="co">    affiliations:</span></span>
<span id="cb66-19"><a href="#cb66-19" aria-hidden="true" tabindex="-1"></a><span class="co">      - ref: cebrap</span></span>
<span id="cb66-20"><a href="#cb66-20" aria-hidden="true" tabindex="-1"></a><span class="co">  - id: mvca</span></span>
<span id="cb66-21"><a href="#cb66-21" aria-hidden="true" tabindex="-1"></a><span class="co">    name: Marcus Vinícius Chevitarese Alves</span></span>
<span id="cb66-22"><a href="#cb66-22" aria-hidden="true" tabindex="-1"></a><span class="co">    email: mchevita@gmail.com</span></span>
<span id="cb66-23"><a href="#cb66-23" aria-hidden="true" tabindex="-1"></a><span class="co">    orcid: 0009-0002-6265-1004</span></span>
<span id="cb66-24"><a href="#cb66-24" aria-hidden="true" tabindex="-1"></a><span class="co">    degrees: PhD</span></span>
<span id="cb66-25"><a href="#cb66-25" aria-hidden="true" tabindex="-1"></a><span class="co">    affiliations:</span></span>
<span id="cb66-26"><a href="#cb66-26" aria-hidden="true" tabindex="-1"></a><span class="co">      - ref: cefor</span></span>
<span id="cb66-27"><a href="#cb66-27" aria-hidden="true" tabindex="-1"></a><span class="co">      - ref: onmp</span></span>
<span id="cb66-28"><a href="#cb66-28" aria-hidden="true" tabindex="-1"></a><span class="co">  - id: vsc</span></span>
<span id="cb66-29"><a href="#cb66-29" aria-hidden="true" tabindex="-1"></a><span class="co">    name: Vanilda Souza Chaves</span></span>
<span id="cb66-30"><a href="#cb66-30" aria-hidden="true" tabindex="-1"></a><span class="co">    email: vanildachaves@gmail.com</span></span>
<span id="cb66-31"><a href="#cb66-31" aria-hidden="true" tabindex="-1"></a><span class="co">    orcid: 0000-0002-0349-3862</span></span>
<span id="cb66-32"><a href="#cb66-32" aria-hidden="true" tabindex="-1"></a><span class="co">    degrees: MsSc</span></span>
<span id="cb66-33"><a href="#cb66-33" aria-hidden="true" tabindex="-1"></a><span class="co">    affiliations:</span></span>
<span id="cb66-34"><a href="#cb66-34" aria-hidden="true" tabindex="-1"></a><span class="co">      - ref: usp</span></span>
<span id="cb66-35"><a href="#cb66-35" aria-hidden="true" tabindex="-1"></a><span class="an">affiliations:</span><span class="co"> </span></span>
<span id="cb66-36"><a href="#cb66-36" aria-hidden="true" tabindex="-1"></a><span class="co">  - id: ufrgs</span></span>
<span id="cb66-37"><a href="#cb66-37" aria-hidden="true" tabindex="-1"></a><span class="co">    name: Federal University of Rio Grande do Sul (UFRGS)</span></span>
<span id="cb66-38"><a href="#cb66-38" aria-hidden="true" tabindex="-1"></a><span class="co">  - id: cebrap</span></span>
<span id="cb66-39"><a href="#cb66-39" aria-hidden="true" tabindex="-1"></a><span class="co">    name: Brazilian Centre for Analysis and Planning (CEBRAP) </span></span>
<span id="cb66-40"><a href="#cb66-40" aria-hidden="true" tabindex="-1"></a><span class="co">  - id: cefor</span></span>
<span id="cb66-41"><a href="#cb66-41" aria-hidden="true" tabindex="-1"></a><span class="co">    name: Center for Training and Improvement - Chamber of Deputies (CEFOR)</span></span>
<span id="cb66-42"><a href="#cb66-42" aria-hidden="true" tabindex="-1"></a><span class="co">  - id: onmp</span></span>
<span id="cb66-43"><a href="#cb66-43" aria-hidden="true" tabindex="-1"></a><span class="co">    name: National Observatory of Women in Politics - Chamber of Deputies (ONMP)</span></span>
<span id="cb66-44"><a href="#cb66-44" aria-hidden="true" tabindex="-1"></a><span class="co">  - id: usp</span></span>
<span id="cb66-45"><a href="#cb66-45" aria-hidden="true" tabindex="-1"></a><span class="co">    name: University of São Paulo (USP)</span></span>
<span id="cb66-46"><a href="#cb66-46" aria-hidden="true" tabindex="-1"></a><span class="co">    </span></span>
<span id="cb66-47"><a href="#cb66-47" aria-hidden="true" tabindex="-1"></a><span class="an">format:</span><span class="co"> </span></span>
<span id="cb66-48"><a href="#cb66-48" aria-hidden="true" tabindex="-1"></a><span class="co">  html:</span></span>
<span id="cb66-49"><a href="#cb66-49" aria-hidden="true" tabindex="-1"></a><span class="co">    toc: true</span></span>
<span id="cb66-50"><a href="#cb66-50" aria-hidden="true" tabindex="-1"></a><span class="co">    code-fold: true</span></span>
<span id="cb66-51"><a href="#cb66-51" aria-hidden="true" tabindex="-1"></a><span class="co">    code-tools: true</span></span>
<span id="cb66-52"><a href="#cb66-52" aria-hidden="true" tabindex="-1"></a><span class="co">    df-print: paged</span></span>
<span id="cb66-53"><a href="#cb66-53" aria-hidden="true" tabindex="-1"></a><span class="co">    link-external-icon: true</span></span>
<span id="cb66-54"><a href="#cb66-54" aria-hidden="true" tabindex="-1"></a><span class="co">    html-math-method: katex</span></span>
<span id="cb66-55"><a href="#cb66-55" aria-hidden="true" tabindex="-1"></a><span class="an">editor:</span><span class="co"> visual</span></span>
<span id="cb66-56"><a href="#cb66-56" aria-hidden="true" tabindex="-1"></a><span class="co">---</span></span>
<span id="cb66-57"><a href="#cb66-57" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-58"><a href="#cb66-58" aria-hidden="true" tabindex="-1"></a><span class="in">```{css, echo = FALSE}</span></span>
<span id="cb66-59"><a href="#cb66-59" aria-hidden="true" tabindex="-1"></a><span class="op">.</span><span class="fu">output</span> <span class="op">{</span></span>
<span id="cb66-60"><a href="#cb66-60" aria-hidden="true" tabindex="-1"></a>max<span class="op">-</span>width<span class="op">:</span> 1000px<span class="op">;</span></span>
<span id="cb66-61"><a href="#cb66-61" aria-hidden="true" tabindex="-1"></a>max<span class="op">-</span>height<span class="op">:</span> 500px<span class="op">;</span></span>
<span id="cb66-62"><a href="#cb66-62" aria-hidden="true" tabindex="-1"></a>overflow<span class="op">-</span>x<span class="op">:</span> scroll<span class="op">;</span></span>
<span id="cb66-63"><a href="#cb66-63" aria-hidden="true" tabindex="-1"></a>overflow<span class="op">-</span>y<span class="op">:</span> scroll<span class="op">;</span></span>
<span id="cb66-64"><a href="#cb66-64" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
<span id="cb66-65"><a href="#cb66-65" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-66"><a href="#cb66-66" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-67"><a href="#cb66-67" aria-hidden="true" tabindex="-1"></a>------------------------------------------------------------------------</span>
<span id="cb66-68"><a href="#cb66-68" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-69"><a href="#cb66-69" aria-hidden="true" tabindex="-1"></a><span class="fu"># Presentation</span></span>
<span id="cb66-70"><a href="#cb66-70" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-71"><a href="#cb66-71" aria-hidden="true" tabindex="-1"></a>We produced this document, in Quarto notebook format as a subsidy for the analysis of data from the article to be published in the Brazilian Journal of Political Science (RBCP).</span>
<span id="cb66-72"><a href="#cb66-72" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-73"><a href="#cb66-73" aria-hidden="true" tabindex="-1"></a>The original data were obtained from the <span class="co">[</span><span class="ot">TSE Open Data Portal</span><span class="co">](https://dadosabertos.tse.jus.br/ "TSE Open Data Portal")</span> and were subsequently subjected to a cleaning and unification process. This process is not entirely covered by this document, which focuses on the analysis of the data itself. However, details about the process can be obtained through the authors' emails.</span>
<span id="cb66-74"><a href="#cb66-74" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-75"><a href="#cb66-75" aria-hidden="true" tabindex="-1"></a><span class="fu"># Objective and hypotheses</span></span>
<span id="cb66-76"><a href="#cb66-76" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-77"><a href="#cb66-77" aria-hidden="true" tabindex="-1"></a>This study aims to conduct an exploratory analysis of the accountability data of candidates for proportional positions (federal deputy and state deputy) in the 2022 elections, comparing them to the data from the 2018 elections and making a gender and color/race cut, with a view to verifying whether there were differences in the distribution of revenues by these groups, in the context of the new electoral legal norms that took effect in the last elections.</span>
<span id="cb66-78"><a href="#cb66-78" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-79"><a href="#cb66-79" aria-hidden="true" tabindex="-1"></a><span class="fu"># Environment setup</span></span>
<span id="cb66-80"><a href="#cb66-80" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-81"><a href="#cb66-81" aria-hidden="true" tabindex="-1"></a><span class="fu">## Clear all objects</span></span>
<span id="cb66-82"><a href="#cb66-82" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-85"><a href="#cb66-85" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-86"><a href="#cb66-86" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-87"><a href="#cb66-87" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-88"><a href="#cb66-88" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: clear-objects</span></span>
<span id="cb66-89"><a href="#cb66-89" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-90"><a href="#cb66-90" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(<span class="at">list=</span><span class="fu">ls</span>())</span>
<span id="cb66-91"><a href="#cb66-91" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-92"><a href="#cb66-92" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-93"><a href="#cb66-93" aria-hidden="true" tabindex="-1"></a><span class="fu">## Load required packages</span></span>
<span id="cb66-94"><a href="#cb66-94" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-97"><a href="#cb66-97" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-98"><a href="#cb66-98" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-99"><a href="#cb66-99" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-100"><a href="#cb66-100" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: load-required-packages</span></span>
<span id="cb66-101"><a href="#cb66-101" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-102"><a href="#cb66-102" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidyr)</span>
<span id="cb66-103"><a href="#cb66-103" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(dplyr)</span>
<span id="cb66-104"><a href="#cb66-104" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(stringr)</span>
<span id="cb66-105"><a href="#cb66-105" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(knitr)</span>
<span id="cb66-106"><a href="#cb66-106" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(DescTools)</span>
<span id="cb66-107"><a href="#cb66-107" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb66-108"><a href="#cb66-108" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(summarytools)</span>
<span id="cb66-109"><a href="#cb66-109" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(afex)</span>
<span id="cb66-110"><a href="#cb66-110" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggpubr)</span>
<span id="cb66-111"><a href="#cb66-111" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(broom)</span>
<span id="cb66-112"><a href="#cb66-112" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(openxlsx)</span>
<span id="cb66-113"><a href="#cb66-113" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(lubridate)</span>
<span id="cb66-114"><a href="#cb66-114" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(scales)</span>
<span id="cb66-115"><a href="#cb66-115" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(patchwork)</span>
<span id="cb66-116"><a href="#cb66-116" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(Cairo)</span>
<span id="cb66-117"><a href="#cb66-117" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(viridis)</span>
<span id="cb66-118"><a href="#cb66-118" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(flextable)</span>
<span id="cb66-119"><a href="#cb66-119" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(officer)</span>
<span id="cb66-120"><a href="#cb66-120" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-121"><a href="#cb66-121" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-122"><a href="#cb66-122" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} length(.packages())`</span> libraries loaded.</span>
<span id="cb66-123"><a href="#cb66-123" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-124"><a href="#cb66-124" aria-hidden="true" tabindex="-1"></a><span class="fu"># Data preparation</span></span>
<span id="cb66-125"><a href="#cb66-125" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-126"><a href="#cb66-126" aria-hidden="true" tabindex="-1"></a>::: callout-note</span>
<span id="cb66-127"><a href="#cb66-127" aria-hidden="true" tabindex="-1"></a>We used three initial datasets in this work: two with campaign revenue data and one with candidate data.</span>
<span id="cb66-128"><a href="#cb66-128" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-129"><a href="#cb66-129" aria-hidden="true" tabindex="-1"></a>The first campaign revenue dataset was aggregated by funding source; the second was aggregated by period (week).</span>
<span id="cb66-130"><a href="#cb66-130" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-131"><a href="#cb66-131" aria-hidden="true" tabindex="-1"></a>We also generated three codebooks, one for each initial dataset. The remaining datasets used in this notebook were based on these.</span>
<span id="cb66-132"><a href="#cb66-132" aria-hidden="true" tabindex="-1"></a>:::</span>
<span id="cb66-133"><a href="#cb66-133" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-134"><a href="#cb66-134" aria-hidden="true" tabindex="-1"></a><span class="fu">## Campaign revenue data preparation</span></span>
<span id="cb66-135"><a href="#cb66-135" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-136"><a href="#cb66-136" aria-hidden="true" tabindex="-1"></a><span class="fu">### Campaign revenue data by source loading</span></span>
<span id="cb66-137"><a href="#cb66-137" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-138"><a href="#cb66-138" aria-hidden="true" tabindex="-1"></a>Upload candidate income data by income source and funding source</span>
<span id="cb66-139"><a href="#cb66-139" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-140"><a href="#cb66-140" aria-hidden="true" tabindex="-1"></a>Data generation date: 2023-09-26</span>
<span id="cb66-141"><a href="#cb66-141" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-144"><a href="#cb66-144" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-145"><a href="#cb66-145" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-146"><a href="#cb66-146" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-147"><a href="#cb66-147" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: campaign-revenue-data-loading</span></span>
<span id="cb66-148"><a href="#cb66-148" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-149"><a href="#cb66-149" aria-hidden="true" tabindex="-1"></a>nome_base_receitas_fonte <span class="ot">&lt;-</span> <span class="st">"../Dados/candidatos_2018_2022_receitas_por_fonte_2023_09_26.dsv"</span></span>
<span id="cb66-150"><a href="#cb66-150" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-151"><a href="#cb66-151" aria-hidden="true" tabindex="-1"></a><span class="co"># Receitas sem formatação prévia</span></span>
<span id="cb66-152"><a href="#cb66-152" aria-hidden="true" tabindex="-1"></a>receitas_fonte <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(</span>
<span id="cb66-153"><a href="#cb66-153" aria-hidden="true" tabindex="-1"></a>  nome_base_receitas_fonte,</span>
<span id="cb66-154"><a href="#cb66-154" aria-hidden="true" tabindex="-1"></a>  <span class="at">header =</span> <span class="cn">TRUE</span>,</span>
<span id="cb66-155"><a href="#cb66-155" aria-hidden="true" tabindex="-1"></a>  <span class="at">sep =</span> <span class="st">";"</span>,                     </span>
<span id="cb66-156"><a href="#cb66-156" aria-hidden="true" tabindex="-1"></a>  <span class="at">fileEncoding =</span> <span class="st">"utf-8"</span>,</span>
<span id="cb66-157"><a href="#cb66-157" aria-hidden="true" tabindex="-1"></a>  <span class="at">dec =</span> <span class="st">","</span>,</span>
<span id="cb66-158"><a href="#cb66-158" aria-hidden="true" tabindex="-1"></a>  <span class="at">stringsAsFactors =</span> <span class="cn">FALSE</span>)</span>
<span id="cb66-159"><a href="#cb66-159" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-160"><a href="#cb66-160" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-161"><a href="#cb66-161" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas_fonte)`</span> lines loaded.</span>
<span id="cb66-162"><a href="#cb66-162" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-163"><a href="#cb66-163" aria-hidden="true" tabindex="-1"></a><span class="fu">### Create the codebook for *receitas_fonte* database</span></span>
<span id="cb66-164"><a href="#cb66-164" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-167"><a href="#cb66-167" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-168"><a href="#cb66-168" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-169"><a href="#cb66-169" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-170"><a href="#cb66-170" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: code-book-1</span></span>
<span id="cb66-171"><a href="#cb66-171" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-172"><a href="#cb66-172" aria-hidden="true" tabindex="-1"></a>descriptions <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">'Election year'</span>,</span>
<span id="cb66-173"><a href="#cb66-173" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Position description'</span>,</span>
<span id="cb66-174"><a href="#cb66-174" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'State acronym'</span>,</span>
<span id="cb66-175"><a href="#cb66-175" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Party acronyn'</span>,</span>
<span id="cb66-176"><a href="#cb66-176" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Candidate name'</span>,</span>
<span id="cb66-177"><a href="#cb66-177" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Candidate ID'</span>,</span>
<span id="cb66-178"><a href="#cb66-178" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Candidate sequential'</span>,</span>
<span id="cb66-179"><a href="#cb66-179" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Candidate gender description'</span>,</span>
<span id="cb66-180"><a href="#cb66-180" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Race description'</span>,</span>
<span id="cb66-181"><a href="#cb66-181" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Revenue source description'</span>,</span>
<span id="cb66-182"><a href="#cb66-182" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Resource source description'</span>,</span>
<span id="cb66-183"><a href="#cb66-183" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Revenue kind description'</span>,</span>
<span id="cb66-184"><a href="#cb66-184" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Donor ID'</span>,</span>
<span id="cb66-185"><a href="#cb66-185" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Campaign accountant ID'</span>,</span>
<span id="cb66-186"><a href="#cb66-186" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Donor candidate sequential'</span>,</span>
<span id="cb66-187"><a href="#cb66-187" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Donor candidate gender'</span>,</span>
<span id="cb66-188"><a href="#cb66-188" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Donor candidate race'</span>,</span>
<span id="cb66-189"><a href="#cb66-189" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Total revenue'</span>,</span>
<span id="cb66-190"><a href="#cb66-190" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Vote tally status'</span>,</span>
<span id="cb66-191"><a href="#cb66-191" aria-hidden="true" tabindex="-1"></a>                  <span class="st">'Reelection status'</span>)</span>
<span id="cb66-192"><a href="#cb66-192" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-193"><a href="#cb66-193" aria-hidden="true" tabindex="-1"></a>code_book_1 <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">variable_name =</span> <span class="fu">names</span>(receitas_fonte),</span>
<span id="cb66-194"><a href="#cb66-194" aria-hidden="true" tabindex="-1"></a>                          <span class="at">variable_class =</span> <span class="fu">sapply</span>(receitas_fonte, class),</span>
<span id="cb66-195"><a href="#cb66-195" aria-hidden="true" tabindex="-1"></a>                          <span class="at">variable_desc =</span> descriptions)</span>
<span id="cb66-196"><a href="#cb66-196" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-197"><a href="#cb66-197" aria-hidden="true" tabindex="-1"></a>code_book_1</span>
<span id="cb66-198"><a href="#cb66-198" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-199"><a href="#cb66-199" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-200"><a href="#cb66-200" aria-hidden="true" tabindex="-1"></a>Save codebook 1</span>
<span id="cb66-201"><a href="#cb66-201" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-204"><a href="#cb66-204" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-205"><a href="#cb66-205" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-206"><a href="#cb66-206" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-207"><a href="#cb66-207" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-codebook-1</span></span>
<span id="cb66-208"><a href="#cb66-208" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-209"><a href="#cb66-209" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(code_book_1, </span>
<span id="cb66-210"><a href="#cb66-210" aria-hidden="true" tabindex="-1"></a>           <span class="st">'..//Dados//Code_Book_1.xlsx'</span>,</span>
<span id="cb66-211"><a href="#cb66-211" aria-hidden="true" tabindex="-1"></a>           <span class="at">sheetName =</span> <span class="st">"codebook1"</span>)</span>
<span id="cb66-212"><a href="#cb66-212" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-213"><a href="#cb66-213" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-214"><a href="#cb66-214" aria-hidden="true" tabindex="-1"></a><span class="fu">### Standardizing campaign revenue data by source</span></span>
<span id="cb66-215"><a href="#cb66-215" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-218"><a href="#cb66-218" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-219"><a href="#cb66-219" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-220"><a href="#cb66-220" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-221"><a href="#cb66-221" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: revenue-data-by-source-standardization</span></span>
<span id="cb66-222"><a href="#cb66-222" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-223"><a href="#cb66-223" aria-hidden="true" tabindex="-1"></a><span class="co"># prepara dados de receitas para a análise</span></span>
<span id="cb66-224"><a href="#cb66-224" aria-hidden="true" tabindex="-1"></a>receitas <span class="ot">&lt;-</span> receitas_fonte <span class="sc">%&gt;%</span></span>
<span id="cb66-225"><a href="#cb66-225" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-226"><a href="#cb66-226" aria-hidden="true" tabindex="-1"></a>    <span class="at">ano_eleicao =</span> <span class="fu">as.factor</span>(ANO_ELEICAO),</span>
<span id="cb66-227"><a href="#cb66-227" aria-hidden="true" tabindex="-1"></a>    <span class="at">NR_CPF_CANDIDATO =</span> <span class="fu">as.character</span>(NR_CPF_CANDIDATO),</span>
<span id="cb66-228"><a href="#cb66-228" aria-hidden="true" tabindex="-1"></a>    <span class="at">uf =</span> <span class="fu">as.factor</span>(SG_UF),</span>
<span id="cb66-229"><a href="#cb66-229" aria-hidden="true" tabindex="-1"></a>    <span class="at">genero =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-230"><a href="#cb66-230" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO) <span class="sc">==</span> <span class="st">'FEMININO'</span> <span class="sc">~</span> <span class="st">'Women'</span>,</span>
<span id="cb66-231"><a href="#cb66-231" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO) <span class="sc">==</span> <span class="st">'MASCULINO'</span> <span class="sc">~</span> <span class="st">'Men'</span>,</span>
<span id="cb66-232"><a href="#cb66-232" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Others'</span></span>
<span id="cb66-233"><a href="#cb66-233" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-234"><a href="#cb66-234" aria-hidden="true" tabindex="-1"></a>    <span class="at">genero_doador =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-235"><a href="#cb66-235" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO_DOADOR) <span class="sc">==</span> <span class="st">'FEMININO'</span> <span class="sc">~</span> <span class="st">'Women'</span>,</span>
<span id="cb66-236"><a href="#cb66-236" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO_DOADOR) <span class="sc">==</span> <span class="st">'MASCULINO'</span> <span class="sc">~</span> <span class="st">'Men'</span>,</span>
<span id="cb66-237"><a href="#cb66-237" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Others'</span></span>
<span id="cb66-238"><a href="#cb66-238" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-239"><a href="#cb66-239" aria-hidden="true" tabindex="-1"></a>    <span class="at">cor_raca =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-240"><a href="#cb66-240" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA <span class="sc">==</span> <span class="st">'PARDA'</span> <span class="sc">|</span> DS_COR_RACA <span class="sc">==</span> <span class="st">'PRETA'</span> <span class="sc">~</span> <span class="st">'Black'</span>,</span>
<span id="cb66-241"><a href="#cb66-241" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA <span class="sc">==</span> <span class="st">'BRANCA'</span> <span class="sc">~</span> <span class="st">'White'</span>,</span>
<span id="cb66-242"><a href="#cb66-242" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Other races'</span></span>
<span id="cb66-243"><a href="#cb66-243" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-244"><a href="#cb66-244" aria-hidden="true" tabindex="-1"></a>    <span class="at">cor_raca_doador =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-245"><a href="#cb66-245" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA_DOADOR <span class="sc">==</span> <span class="st">'PARDA'</span> <span class="sc">|</span> DS_COR_RACA_DOADOR <span class="sc">==</span> <span class="st">'PRETA'</span> <span class="sc">~</span> <span class="st">'Black'</span>,</span>
<span id="cb66-246"><a href="#cb66-246" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA_DOADOR <span class="sc">==</span> <span class="st">'BRANCA'</span> <span class="sc">~</span> <span class="st">'White'</span>,</span>
<span id="cb66-247"><a href="#cb66-247" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Other races'</span></span>
<span id="cb66-248"><a href="#cb66-248" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-249"><a href="#cb66-249" aria-hidden="true" tabindex="-1"></a>    <span class="at">eleito =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-250"><a href="#cb66-250" aria-hidden="true" tabindex="-1"></a>      DS_SIT_TOT_TURNO <span class="sc">%like%</span> <span class="st">'ELEITO%'</span> <span class="sc">~</span> <span class="st">'Elected'</span>,</span>
<span id="cb66-251"><a href="#cb66-251" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Not elected'</span></span>
<span id="cb66-252"><a href="#cb66-252" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-253"><a href="#cb66-253" aria-hidden="true" tabindex="-1"></a>    <span class="at">fonte_receita =</span> <span class="fu">str_to_upper</span>(DS_FONTE_RECEITA),</span>
<span id="cb66-254"><a href="#cb66-254" aria-hidden="true" tabindex="-1"></a>    <span class="at">tipo_fonte_receita =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-255"><a href="#cb66-255" aria-hidden="true" tabindex="-1"></a>      fonte_receita <span class="sc">==</span> <span class="st">'FUNDO ESPECIAL'</span> <span class="sc">~</span> <span class="st">'FEFC'</span>,</span>
<span id="cb66-256"><a href="#cb66-256" aria-hidden="true" tabindex="-1"></a>      fonte_receita <span class="sc">==</span> <span class="st">'FUNDO PARTIDARIO'</span> <span class="sc">~</span> <span class="st">'FP'</span>,</span>
<span id="cb66-257"><a href="#cb66-257" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Outros recursos'</span></span>
<span id="cb66-258"><a href="#cb66-258" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-259"><a href="#cb66-259" aria-hidden="true" tabindex="-1"></a>    <span class="at">tipo_recurso =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-260"><a href="#cb66-260" aria-hidden="true" tabindex="-1"></a>      tipo_fonte_receita <span class="sc">==</span> <span class="st">'Outros recursos'</span> <span class="sc">~</span> <span class="st">'Private'</span>,</span>
<span id="cb66-261"><a href="#cb66-261" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Public'</span></span>
<span id="cb66-262"><a href="#cb66-262" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-263"><a href="#cb66-263" aria-hidden="true" tabindex="-1"></a>    <span class="at">especie_recurso =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-264"><a href="#cb66-264" aria-hidden="true" tabindex="-1"></a>      DS_ESPECIE_RECEITA <span class="sc">==</span> <span class="st">'Estimado'</span> <span class="sc">~</span> <span class="st">'Cash-equivalent'</span>,</span>
<span id="cb66-265"><a href="#cb66-265" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Cash'</span></span>
<span id="cb66-266"><a href="#cb66-266" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb66-267"><a href="#cb66-267" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb66-268"><a href="#cb66-268" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-269"><a href="#cb66-269" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(receitas_fonte)</span>
<span id="cb66-270"><a href="#cb66-270" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-271"><a href="#cb66-271" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-272"><a href="#cb66-272" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas)`</span> lines standardized.</span>
<span id="cb66-273"><a href="#cb66-273" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-274"><a href="#cb66-274" aria-hidden="true" tabindex="-1"></a><span class="fu">### Loading campaign resource data by time</span></span>
<span id="cb66-275"><a href="#cb66-275" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-276"><a href="#cb66-276" aria-hidden="true" tabindex="-1"></a>Uploads a database of income from eligible candidates with detailed declared income by time, in 2018 and 2022</span>
<span id="cb66-277"><a href="#cb66-277" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-280"><a href="#cb66-280" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-281"><a href="#cb66-281" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-282"><a href="#cb66-282" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-283"><a href="#cb66-283" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: campaign-resource-data-by-time-loading</span></span>
<span id="cb66-284"><a href="#cb66-284" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-285"><a href="#cb66-285" aria-hidden="true" tabindex="-1"></a>nome_base_receitas <span class="ot">&lt;-</span> <span class="st">"../Dados/receitas_por_data_e_origem_2018_2022_v_2023_09_27.dsv"</span></span>
<span id="cb66-286"><a href="#cb66-286" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-287"><a href="#cb66-287" aria-hidden="true" tabindex="-1"></a><span class="co"># Database with raw data</span></span>
<span id="cb66-288"><a href="#cb66-288" aria-hidden="true" tabindex="-1"></a>receitas_por_tempo_sem_form <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(</span>
<span id="cb66-289"><a href="#cb66-289" aria-hidden="true" tabindex="-1"></a>  nome_base_receitas,</span>
<span id="cb66-290"><a href="#cb66-290" aria-hidden="true" tabindex="-1"></a>  <span class="at">header =</span> <span class="cn">TRUE</span>,</span>
<span id="cb66-291"><a href="#cb66-291" aria-hidden="true" tabindex="-1"></a>  <span class="at">sep =</span> <span class="st">";"</span>,                     </span>
<span id="cb66-292"><a href="#cb66-292" aria-hidden="true" tabindex="-1"></a>  <span class="at">fileEncoding =</span> <span class="st">"utf-8"</span>,</span>
<span id="cb66-293"><a href="#cb66-293" aria-hidden="true" tabindex="-1"></a>  <span class="at">dec =</span> <span class="st">","</span>,</span>
<span id="cb66-294"><a href="#cb66-294" aria-hidden="true" tabindex="-1"></a>  <span class="at">stringsAsFactors =</span> <span class="cn">FALSE</span>,</span>
<span id="cb66-295"><a href="#cb66-295" aria-hidden="true" tabindex="-1"></a>  <span class="at">colClasses=</span><span class="fu">c</span>(<span class="st">"NR_CPF_CANDIDATO"</span><span class="ot">=</span><span class="st">"character"</span>))</span>
<span id="cb66-296"><a href="#cb66-296" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-297"><a href="#cb66-297" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-298"><a href="#cb66-298" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas_por_tempo_sem_form)`</span> lines loaded.</span>
<span id="cb66-299"><a href="#cb66-299" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-300"><a href="#cb66-300" aria-hidden="true" tabindex="-1"></a><span class="fu">### Create the codebook for *receitas_por_tempo_sem_form* database</span></span>
<span id="cb66-301"><a href="#cb66-301" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-304"><a href="#cb66-304" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-305"><a href="#cb66-305" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-306"><a href="#cb66-306" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-307"><a href="#cb66-307" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: code-book-2</span></span>
<span id="cb66-308"><a href="#cb66-308" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-309"><a href="#cb66-309" aria-hidden="true" tabindex="-1"></a>descriptions_2 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">'Election year'</span>,</span>
<span id="cb66-310"><a href="#cb66-310" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Position description'</span>,</span>
<span id="cb66-311"><a href="#cb66-311" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'State acronym'</span>,</span>
<span id="cb66-312"><a href="#cb66-312" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Revenue source description'</span>,</span>
<span id="cb66-313"><a href="#cb66-313" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Resource source description'</span>,</span>
<span id="cb66-314"><a href="#cb66-314" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Revenue kind description'</span>,</span>
<span id="cb66-315"><a href="#cb66-315" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Revenue date'</span>,</span>
<span id="cb66-316"><a href="#cb66-316" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Candidate sequential'</span>,</span>
<span id="cb66-317"><a href="#cb66-317" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Candidate ID'</span>,</span>
<span id="cb66-318"><a href="#cb66-318" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Total revenue'</span>)</span>
<span id="cb66-319"><a href="#cb66-319" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-320"><a href="#cb66-320" aria-hidden="true" tabindex="-1"></a>code_book_2 <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(</span>
<span id="cb66-321"><a href="#cb66-321" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_name =</span> <span class="fu">names</span>(receitas_por_tempo_sem_form),</span>
<span id="cb66-322"><a href="#cb66-322" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_class =</span> <span class="fu">sapply</span>(receitas_por_tempo_sem_form, class),</span>
<span id="cb66-323"><a href="#cb66-323" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_desc =</span> descriptions_2)</span>
<span id="cb66-324"><a href="#cb66-324" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-325"><a href="#cb66-325" aria-hidden="true" tabindex="-1"></a>code_book_2 <span class="sc">%&gt;%</span> </span>
<span id="cb66-326"><a href="#cb66-326" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(variable_name, </span>
<span id="cb66-327"><a href="#cb66-327" aria-hidden="true" tabindex="-1"></a>         variable_class, </span>
<span id="cb66-328"><a href="#cb66-328" aria-hidden="true" tabindex="-1"></a>         variable_desc)</span>
<span id="cb66-329"><a href="#cb66-329" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-330"><a href="#cb66-330" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-331"><a href="#cb66-331" aria-hidden="true" tabindex="-1"></a>Save codebook 2</span>
<span id="cb66-332"><a href="#cb66-332" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-335"><a href="#cb66-335" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-336"><a href="#cb66-336" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-337"><a href="#cb66-337" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-338"><a href="#cb66-338" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-codebook-2</span></span>
<span id="cb66-339"><a href="#cb66-339" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-340"><a href="#cb66-340" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(code_book_2, </span>
<span id="cb66-341"><a href="#cb66-341" aria-hidden="true" tabindex="-1"></a>           <span class="st">'..//Dados//Code_Book_2.xlsx'</span>,</span>
<span id="cb66-342"><a href="#cb66-342" aria-hidden="true" tabindex="-1"></a>           <span class="at">sheetName =</span> <span class="st">"codebook2"</span>)</span>
<span id="cb66-343"><a href="#cb66-343" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-344"><a href="#cb66-344" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-345"><a href="#cb66-345" aria-hidden="true" tabindex="-1"></a><span class="fu">## Candidacy data</span></span>
<span id="cb66-346"><a href="#cb66-346" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-347"><a href="#cb66-347" aria-hidden="true" tabindex="-1"></a>It loads the database of candidates in 2018 and 2022 and shows the overall total of candidates -- in this case, no filter was applied, therefore, candidates classified as "irregular" by the TSE were also considered.</span>
<span id="cb66-348"><a href="#cb66-348" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-349"><a href="#cb66-349" aria-hidden="true" tabindex="-1"></a><span class="fu">### Loading candidacy data</span></span>
<span id="cb66-350"><a href="#cb66-350" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-353"><a href="#cb66-353" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-354"><a href="#cb66-354" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-355"><a href="#cb66-355" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-356"><a href="#cb66-356" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: candidacy-data-loading</span></span>
<span id="cb66-357"><a href="#cb66-357" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-358"><a href="#cb66-358" aria-hidden="true" tabindex="-1"></a>nome_base_candidatos <span class="ot">&lt;-</span> <span class="st">"../Dados/candidatos_2018_2022_v_2023_09_27.dsv"</span></span>
<span id="cb66-359"><a href="#cb66-359" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-360"><a href="#cb66-360" aria-hidden="true" tabindex="-1"></a>candidatos_sem_form <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(</span>
<span id="cb66-361"><a href="#cb66-361" aria-hidden="true" tabindex="-1"></a>  nome_base_candidatos,</span>
<span id="cb66-362"><a href="#cb66-362" aria-hidden="true" tabindex="-1"></a>  <span class="at">header =</span> <span class="cn">TRUE</span>,</span>
<span id="cb66-363"><a href="#cb66-363" aria-hidden="true" tabindex="-1"></a>  <span class="at">sep =</span> <span class="st">";"</span>,                     </span>
<span id="cb66-364"><a href="#cb66-364" aria-hidden="true" tabindex="-1"></a>  <span class="at">fileEncoding =</span> <span class="st">"utf-8"</span>,</span>
<span id="cb66-365"><a href="#cb66-365" aria-hidden="true" tabindex="-1"></a>  <span class="at">stringsAsFactors =</span> <span class="cn">FALSE</span>,</span>
<span id="cb66-366"><a href="#cb66-366" aria-hidden="true" tabindex="-1"></a>  <span class="at">colClasses=</span><span class="fu">c</span>(<span class="st">"NR_CPF_CANDIDATO"</span><span class="ot">=</span><span class="st">"character"</span>))</span>
<span id="cb66-367"><a href="#cb66-367" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-368"><a href="#cb66-368" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-369"><a href="#cb66-369" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(candidatos_sem_form)`</span> lines loaded.</span>
<span id="cb66-370"><a href="#cb66-370" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-373"><a href="#cb66-373" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-374"><a href="#cb66-374" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-375"><a href="#cb66-375" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-376"><a href="#cb66-376" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: code-book-3</span></span>
<span id="cb66-377"><a href="#cb66-377" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-378"><a href="#cb66-378" aria-hidden="true" tabindex="-1"></a>descriptions_3 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"Election year"</span>,</span>
<span id="cb66-379"><a href="#cb66-379" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"State name"</span>,</span>
<span id="cb66-380"><a href="#cb66-380" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"State acronym"</span>,</span>
<span id="cb66-381"><a href="#cb66-381" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Position description"</span>,</span>
<span id="cb66-382"><a href="#cb66-382" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Party acronyn"</span>,</span>
<span id="cb66-383"><a href="#cb66-383" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidate name"</span>,</span>
<span id="cb66-384"><a href="#cb66-384" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidate's ballot box name"</span>,</span>
<span id="cb66-385"><a href="#cb66-385" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidate sequential ID"</span>,</span>
<span id="cb66-386"><a href="#cb66-386" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidate ID"</span>,</span>
<span id="cb66-387"><a href="#cb66-387" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidacy status description"</span>,</span>
<span id="cb66-388"><a href="#cb66-388" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidacy detailed status description"</span>,</span>
<span id="cb66-389"><a href="#cb66-389" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Vote tally status"</span>,</span>
<span id="cb66-390"><a href="#cb66-390" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Nationality of the candidate"</span>,</span>
<span id="cb66-391"><a href="#cb66-391" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Acronym of place (state) of birth"</span>,</span>
<span id="cb66-392"><a href="#cb66-392" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Date of birth"</span>,</span>
<span id="cb66-393"><a href="#cb66-393" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Age at the time of taking office"</span>,</span>
<span id="cb66-394"><a href="#cb66-394" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Vote registration number"</span>,</span>
<span id="cb66-395"><a href="#cb66-395" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Candidate gender description"</span>,</span>
<span id="cb66-396"><a href="#cb66-396" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Education level description"</span>,</span>
<span id="cb66-397"><a href="#cb66-397" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Race code"</span>,</span>
<span id="cb66-398"><a href="#cb66-398" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Race description"</span>,</span>
<span id="cb66-399"><a href="#cb66-399" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Occupation code"</span>,</span>
<span id="cb66-400"><a href="#cb66-400" aria-hidden="true" tabindex="-1"></a>                    <span class="st">"Occupation description"</span>,</span>
<span id="cb66-401"><a href="#cb66-401" aria-hidden="true" tabindex="-1"></a>                    <span class="st">'Reelection status'</span>)</span>
<span id="cb66-402"><a href="#cb66-402" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-403"><a href="#cb66-403" aria-hidden="true" tabindex="-1"></a>code_book_3 <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(</span>
<span id="cb66-404"><a href="#cb66-404" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_name =</span> <span class="fu">names</span>(candidatos_sem_form),</span>
<span id="cb66-405"><a href="#cb66-405" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_class =</span> <span class="fu">sapply</span>(candidatos_sem_form, class),</span>
<span id="cb66-406"><a href="#cb66-406" aria-hidden="true" tabindex="-1"></a>  <span class="at">variable_desc =</span> descriptions_3)</span>
<span id="cb66-407"><a href="#cb66-407" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-408"><a href="#cb66-408" aria-hidden="true" tabindex="-1"></a>code_book_3</span>
<span id="cb66-409"><a href="#cb66-409" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-410"><a href="#cb66-410" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-411"><a href="#cb66-411" aria-hidden="true" tabindex="-1"></a>Save codebook 3</span>
<span id="cb66-412"><a href="#cb66-412" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-415"><a href="#cb66-415" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-416"><a href="#cb66-416" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-417"><a href="#cb66-417" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-418"><a href="#cb66-418" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-codebook-3</span></span>
<span id="cb66-419"><a href="#cb66-419" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-420"><a href="#cb66-420" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(code_book_3, </span>
<span id="cb66-421"><a href="#cb66-421" aria-hidden="true" tabindex="-1"></a>           <span class="st">'..//Dados//Code_Book_3.xlsx'</span>,</span>
<span id="cb66-422"><a href="#cb66-422" aria-hidden="true" tabindex="-1"></a>           <span class="at">sheetName =</span> <span class="st">"codebook3"</span>)</span>
<span id="cb66-423"><a href="#cb66-423" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-424"><a href="#cb66-424" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-425"><a href="#cb66-425" aria-hidden="true" tabindex="-1"></a><span class="fu">## Data preparation</span></span>
<span id="cb66-426"><a href="#cb66-426" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-427"><a href="#cb66-427" aria-hidden="true" tabindex="-1"></a><span class="fu">### Standardizing variable names</span></span>
<span id="cb66-428"><a href="#cb66-428" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-429"><a href="#cb66-429" aria-hidden="true" tabindex="-1"></a>We made some changes to the names of the original TSE variables, as well as some aggregations and formatting to simplifly the analysis. Both the original and new names are kept in Brazilian Portuguese.</span>
<span id="cb66-430"><a href="#cb66-430" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-431"><a href="#cb66-431" aria-hidden="true" tabindex="-1"></a>+--------------------+--------------------+------------------------------------------------------------------------------+</span>
<span id="cb66-432"><a href="#cb66-432" aria-hidden="true" tabindex="-1"></a>| Original name      | New name           | Other modifications                                                          |</span>
<span id="cb66-433"><a href="#cb66-433" aria-hidden="true" tabindex="-1"></a>+====================+====================+==============================================================================+</span>
<span id="cb66-434"><a href="#cb66-434" aria-hidden="true" tabindex="-1"></a>| ANO_ELEICAO        | ano_eleicao        | --                                                                           |</span>
<span id="cb66-435"><a href="#cb66-435" aria-hidden="true" tabindex="-1"></a>+--------------------+--------------------+------------------------------------------------------------------------------+</span>
<span id="cb66-436"><a href="#cb66-436" aria-hidden="true" tabindex="-1"></a>| SG_UF              | uf                 | --                                                                           |</span>
<span id="cb66-437"><a href="#cb66-437" aria-hidden="true" tabindex="-1"></a>+--------------------+--------------------+------------------------------------------------------------------------------+</span>
<span id="cb66-438"><a href="#cb66-438" aria-hidden="true" tabindex="-1"></a>| DT_RECEITA         | data_receita       | Conversion to format dd/mm/aaaa                                              |</span>
<span id="cb66-439"><a href="#cb66-439" aria-hidden="true" tabindex="-1"></a>+--------------------+--------------------+------------------------------------------------------------------------------+</span>
<span id="cb66-440"><a href="#cb66-440" aria-hidden="true" tabindex="-1"></a>| DS_CARGO           | cargo              | --                                                                           |</span>
<span id="cb66-441"><a href="#cb66-441" aria-hidden="true" tabindex="-1"></a>+--------------------+--------------------+------------------------------------------------------------------------------+</span>
<span id="cb66-442"><a href="#cb66-442" aria-hidden="true" tabindex="-1"></a>| DS_GENERO          | genero             | Removing blanking spaces                                                     |</span>
<span id="cb66-443"><a href="#cb66-443" aria-hidden="true" tabindex="-1"></a>+--------------------+--------------------+------------------------------------------------------------------------------+</span>
<span id="cb66-444"><a href="#cb66-444" aria-hidden="true" tabindex="-1"></a>| DS_COR_RACA        | cor_raca           | If DS_COR_RACA = 'PARDA' or 'PRETA' then cor_raca = 'Blak'                   |</span>
<span id="cb66-445"><a href="#cb66-445" aria-hidden="true" tabindex="-1"></a>|                    |                    |                                                                              |</span>
<span id="cb66-446"><a href="#cb66-446" aria-hidden="true" tabindex="-1"></a>|                    |                    | If DS_COR_RACA = 'BRANCA' then cor_raca = 'White'                            |</span>
<span id="cb66-447"><a href="#cb66-447" aria-hidden="true" tabindex="-1"></a>|                    |                    |                                                                              |</span>
<span id="cb66-448"><a href="#cb66-448" aria-hidden="true" tabindex="-1"></a>|                    |                    | Else cor_raca = 'Other races'                                                |</span>
<span id="cb66-449"><a href="#cb66-449" aria-hidden="true" tabindex="-1"></a>+--------------------+--------------------+------------------------------------------------------------------------------+</span>
<span id="cb66-450"><a href="#cb66-450" aria-hidden="true" tabindex="-1"></a>| DS_SIT_TOT_TURNO   | eleito             | If DS_SIT_TURNO = 'Eleito%' then eleito = 'Elected'                          |</span>
<span id="cb66-451"><a href="#cb66-451" aria-hidden="true" tabindex="-1"></a>|                    |                    |                                                                              |</span>
<span id="cb66-452"><a href="#cb66-452" aria-hidden="true" tabindex="-1"></a>|                    |                    | Else eleito = 'Not elected'                                                  |</span>
<span id="cb66-453"><a href="#cb66-453" aria-hidden="true" tabindex="-1"></a>+--------------------+--------------------+------------------------------------------------------------------------------+</span>
<span id="cb66-454"><a href="#cb66-454" aria-hidden="true" tabindex="-1"></a>| --                 | tipo_fonte_receita | If fonte_receita = 'FUNDO ESPECIAL' then tIpo_fonte_receita = 'FEFC'         |</span>
<span id="cb66-455"><a href="#cb66-455" aria-hidden="true" tabindex="-1"></a>|                    |                    |                                                                              |</span>
<span id="cb66-456"><a href="#cb66-456" aria-hidden="true" tabindex="-1"></a>|                    |                    | If fonte_receita = 'FUNDO PARTIDARIO' then tipo_fonte_receita = 'FP'         |</span>
<span id="cb66-457"><a href="#cb66-457" aria-hidden="true" tabindex="-1"></a>|                    |                    |                                                                              |</span>
<span id="cb66-458"><a href="#cb66-458" aria-hidden="true" tabindex="-1"></a>|                    |                    | Else tipo_fonte_receita = 'Outros recursos'                                  |</span>
<span id="cb66-459"><a href="#cb66-459" aria-hidden="true" tabindex="-1"></a>+--------------------+--------------------+------------------------------------------------------------------------------+</span>
<span id="cb66-460"><a href="#cb66-460" aria-hidden="true" tabindex="-1"></a>| DS_ESPECIE_RECEITA | especie_receita    | If DS_ESPECIE_RECEITA = 'Estimado' então especie_receita = 'Cash-equivalent' |</span>
<span id="cb66-461"><a href="#cb66-461" aria-hidden="true" tabindex="-1"></a>|                    |                    |                                                                              |</span>
<span id="cb66-462"><a href="#cb66-462" aria-hidden="true" tabindex="-1"></a>|                    |                    | Then especie_receita = 'Cash'                                                |</span>
<span id="cb66-463"><a href="#cb66-463" aria-hidden="true" tabindex="-1"></a>+--------------------+--------------------+------------------------------------------------------------------------------+</span>
<span id="cb66-464"><a href="#cb66-464" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-465"><a href="#cb66-465" aria-hidden="true" tabindex="-1"></a><span class="fu">### Standardizing campaign revenue data by time</span></span>
<span id="cb66-466"><a href="#cb66-466" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-469"><a href="#cb66-469" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-470"><a href="#cb66-470" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-471"><a href="#cb66-471" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-472"><a href="#cb66-472" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: campaign-revenue-data-standardization</span></span>
<span id="cb66-473"><a href="#cb66-473" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-474"><a href="#cb66-474" aria-hidden="true" tabindex="-1"></a><span class="co"># prepara dados de receitas para a análise</span></span>
<span id="cb66-475"><a href="#cb66-475" aria-hidden="true" tabindex="-1"></a>receitas_por_tempo <span class="ot">&lt;-</span> receitas_por_tempo_sem_form <span class="sc">%&gt;%</span></span>
<span id="cb66-476"><a href="#cb66-476" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">fonte_receita =</span> <span class="fu">str_to_upper</span>(DS_FONTE_RECEITA)) <span class="sc">%&gt;%</span></span>
<span id="cb66-477"><a href="#cb66-477" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-478"><a href="#cb66-478" aria-hidden="true" tabindex="-1"></a>    <span class="at">ano_eleicao =</span> <span class="fu">as.factor</span>(ANO_ELEICAO),</span>
<span id="cb66-479"><a href="#cb66-479" aria-hidden="true" tabindex="-1"></a>    <span class="at">cargo =</span> <span class="fu">str_to_upper</span>(DS_CARGO),</span>
<span id="cb66-480"><a href="#cb66-480" aria-hidden="true" tabindex="-1"></a>    <span class="at">uf =</span> <span class="fu">as.factor</span>(SG_UF),</span>
<span id="cb66-481"><a href="#cb66-481" aria-hidden="true" tabindex="-1"></a>    <span class="at">sq_candidato =</span> SQ_CANDIDATO,</span>
<span id="cb66-482"><a href="#cb66-482" aria-hidden="true" tabindex="-1"></a>    <span class="at">cpf_candidato =</span> <span class="fu">as.character</span>(NR_CPF_CANDIDATO),</span>
<span id="cb66-483"><a href="#cb66-483" aria-hidden="true" tabindex="-1"></a>    <span class="at">data_receita =</span> <span class="fu">as.Date</span>(DT_RECEITA, <span class="st">"%d/%m/%Y"</span>),</span>
<span id="cb66-484"><a href="#cb66-484" aria-hidden="true" tabindex="-1"></a>    <span class="at">tipo_fonte_receita =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-485"><a href="#cb66-485" aria-hidden="true" tabindex="-1"></a>      fonte_receita <span class="sc">==</span> <span class="st">'FUNDO ESPECIAL'</span> <span class="sc">~</span> <span class="st">'FEFC'</span>,</span>
<span id="cb66-486"><a href="#cb66-486" aria-hidden="true" tabindex="-1"></a>      fonte_receita <span class="sc">==</span> <span class="st">'FUNDO PARTIDARIO'</span> <span class="sc">~</span> <span class="st">'FP'</span>,</span>
<span id="cb66-487"><a href="#cb66-487" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Outros recursos'</span></span>
<span id="cb66-488"><a href="#cb66-488" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-489"><a href="#cb66-489" aria-hidden="true" tabindex="-1"></a>    <span class="at">especie_receita =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-490"><a href="#cb66-490" aria-hidden="true" tabindex="-1"></a>      DS_ESPECIE_RECEITA <span class="sc">==</span> <span class="st">'Estimado'</span> <span class="sc">~</span> <span class="st">'Cash-equivalent'</span>,</span>
<span id="cb66-491"><a href="#cb66-491" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Cash'</span>),</span>
<span id="cb66-492"><a href="#cb66-492" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receita_especie =</span> TOTAL_RECEITA</span>
<span id="cb66-493"><a href="#cb66-493" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb66-494"><a href="#cb66-494" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-495"><a href="#cb66-495" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(receitas_por_tempo_sem_form)</span>
<span id="cb66-496"><a href="#cb66-496" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-497"><a href="#cb66-497" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-498"><a href="#cb66-498" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas_por_tempo)`</span> lines standardized.</span>
<span id="cb66-499"><a href="#cb66-499" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-500"><a href="#cb66-500" aria-hidden="true" tabindex="-1"></a><span class="fu">### Standardizing candidacies data</span></span>
<span id="cb66-501"><a href="#cb66-501" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-504"><a href="#cb66-504" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-505"><a href="#cb66-505" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-506"><a href="#cb66-506" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-507"><a href="#cb66-507" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: candidacies-data-standardization</span></span>
<span id="cb66-508"><a href="#cb66-508" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-509"><a href="#cb66-509" aria-hidden="true" tabindex="-1"></a><span class="co"># prepara dados de candidatos para a análise</span></span>
<span id="cb66-510"><a href="#cb66-510" aria-hidden="true" tabindex="-1"></a>candidatos <span class="ot">&lt;-</span> candidatos_sem_form <span class="sc">%&gt;%</span></span>
<span id="cb66-511"><a href="#cb66-511" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(DS_SITUACAO_CANDIDATURA <span class="sc">==</span> <span class="st">"APTO"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-512"><a href="#cb66-512" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-513"><a href="#cb66-513" aria-hidden="true" tabindex="-1"></a>    <span class="at">ano_eleicao =</span> <span class="fu">as.factor</span>(ANO_ELEICAO),</span>
<span id="cb66-514"><a href="#cb66-514" aria-hidden="true" tabindex="-1"></a>    <span class="at">uf =</span> <span class="fu">as.factor</span>(SG_UF),</span>
<span id="cb66-515"><a href="#cb66-515" aria-hidden="true" tabindex="-1"></a>    <span class="at">cargo =</span> <span class="fu">str_to_upper</span>(DS_CARGO_CONCORRIDO),</span>
<span id="cb66-516"><a href="#cb66-516" aria-hidden="true" tabindex="-1"></a>    <span class="at">partido =</span> SG_PARTIDO,</span>
<span id="cb66-517"><a href="#cb66-517" aria-hidden="true" tabindex="-1"></a>    <span class="at">cpf_candidato =</span> <span class="fu">as.character</span>(NR_CPF_CANDIDATO),</span>
<span id="cb66-518"><a href="#cb66-518" aria-hidden="true" tabindex="-1"></a>    <span class="at">sq_candidato =</span> SQ_CANDIDATO,</span>
<span id="cb66-519"><a href="#cb66-519" aria-hidden="true" tabindex="-1"></a>    <span class="at">genero =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-520"><a href="#cb66-520" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO) <span class="sc">==</span> <span class="st">'FEMININO'</span> <span class="sc">~</span> <span class="st">'Women'</span>,</span>
<span id="cb66-521"><a href="#cb66-521" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(DS_GENERO) <span class="sc">==</span> <span class="st">'MASCULINO'</span> <span class="sc">~</span> <span class="st">'Men'</span>,</span>
<span id="cb66-522"><a href="#cb66-522" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Others'</span></span>
<span id="cb66-523"><a href="#cb66-523" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-524"><a href="#cb66-524" aria-hidden="true" tabindex="-1"></a>    <span class="at">cor_raca =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-525"><a href="#cb66-525" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA <span class="sc">==</span> <span class="st">'PARDA'</span> <span class="sc">|</span> DS_COR_RACA <span class="sc">==</span> <span class="st">'PRETA'</span> <span class="sc">~</span> <span class="st">'Black'</span>,</span>
<span id="cb66-526"><a href="#cb66-526" aria-hidden="true" tabindex="-1"></a>      DS_COR_RACA <span class="sc">==</span> <span class="st">'BRANCA'</span> <span class="sc">~</span> <span class="st">'White'</span>,</span>
<span id="cb66-527"><a href="#cb66-527" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Other races'</span></span>
<span id="cb66-528"><a href="#cb66-528" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-529"><a href="#cb66-529" aria-hidden="true" tabindex="-1"></a>    <span class="at">eleito =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-530"><a href="#cb66-530" aria-hidden="true" tabindex="-1"></a>      DS_SIT_TOT_TURNO <span class="sc">%like%</span> <span class="st">'ELEITO%'</span> <span class="sc">~</span> <span class="st">'Elected'</span>,</span>
<span id="cb66-531"><a href="#cb66-531" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Not elected'</span></span>
<span id="cb66-532"><a href="#cb66-532" aria-hidden="true" tabindex="-1"></a>    ),</span>
<span id="cb66-533"><a href="#cb66-533" aria-hidden="true" tabindex="-1"></a>    <span class="at">reeleicao =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-534"><a href="#cb66-534" aria-hidden="true" tabindex="-1"></a>      <span class="fu">str_trim</span>(ST_REELEICAO) <span class="sc">==</span> <span class="st">'N'</span> <span class="sc">~</span> <span class="st">'Challenger'</span>,</span>
<span id="cb66-535"><a href="#cb66-535" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span> <span class="sc">~</span> <span class="st">'Reelection'</span></span>
<span id="cb66-536"><a href="#cb66-536" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb66-537"><a href="#cb66-537" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb66-538"><a href="#cb66-538" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-539"><a href="#cb66-539" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(candidatos_sem_form)</span>
<span id="cb66-540"><a href="#cb66-540" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-541"><a href="#cb66-541" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-542"><a href="#cb66-542" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(candidatos)`</span> lines standardized.</span>
<span id="cb66-543"><a href="#cb66-543" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-544"><a href="#cb66-544" aria-hidden="true" tabindex="-1"></a><span class="fu">### Data aggregation</span></span>
<span id="cb66-545"><a href="#cb66-545" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-546"><a href="#cb66-546" aria-hidden="true" tabindex="-1"></a><span class="fu">#### Step 1 - Combining campaign revenue and candidate data</span></span>
<span id="cb66-547"><a href="#cb66-547" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-548"><a href="#cb66-548" aria-hidden="true" tabindex="-1"></a>In this step, we join revenue and candidacies data to calculate the proportion of candidates. This is necessary because not all candidates necessarily submit financial statements, as they may have their candidacy registration denied or even withdraw their candidacy.</span>
<span id="cb66-549"><a href="#cb66-549" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-552"><a href="#cb66-552" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-553"><a href="#cb66-553" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-554"><a href="#cb66-554" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-555"><a href="#cb66-555" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: revenues-candidacies-join</span></span>
<span id="cb66-556"><a href="#cb66-556" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-557"><a href="#cb66-557" aria-hidden="true" tabindex="-1"></a>receitas_candidatos_por_tempo <span class="ot">&lt;-</span> candidatos <span class="sc">%&gt;%</span></span>
<span id="cb66-558"><a href="#cb66-558" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb66-559"><a href="#cb66-559" aria-hidden="true" tabindex="-1"></a>    ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>), </span>
<span id="cb66-560"><a href="#cb66-560" aria-hidden="true" tabindex="-1"></a>    cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO DISTRITAL'</span>, </span>
<span id="cb66-561"><a href="#cb66-561" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO ESTADUAL'</span>, </span>
<span id="cb66-562"><a href="#cb66-562" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO FEDERAL'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb66-563"><a href="#cb66-563" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(</span>
<span id="cb66-564"><a href="#cb66-564" aria-hidden="true" tabindex="-1"></a>    ano_eleicao, </span>
<span id="cb66-565"><a href="#cb66-565" aria-hidden="true" tabindex="-1"></a>    uf, </span>
<span id="cb66-566"><a href="#cb66-566" aria-hidden="true" tabindex="-1"></a>    cargo, </span>
<span id="cb66-567"><a href="#cb66-567" aria-hidden="true" tabindex="-1"></a>    partido, </span>
<span id="cb66-568"><a href="#cb66-568" aria-hidden="true" tabindex="-1"></a>    sq_candidato,</span>
<span id="cb66-569"><a href="#cb66-569" aria-hidden="true" tabindex="-1"></a>    cpf_candidato, </span>
<span id="cb66-570"><a href="#cb66-570" aria-hidden="true" tabindex="-1"></a>    genero, </span>
<span id="cb66-571"><a href="#cb66-571" aria-hidden="true" tabindex="-1"></a>    cor_raca,</span>
<span id="cb66-572"><a href="#cb66-572" aria-hidden="true" tabindex="-1"></a>    eleito,</span>
<span id="cb66-573"><a href="#cb66-573" aria-hidden="true" tabindex="-1"></a>    reeleicao) <span class="sc">%&gt;%</span> </span>
<span id="cb66-574"><a href="#cb66-574" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(</span>
<span id="cb66-575"><a href="#cb66-575" aria-hidden="true" tabindex="-1"></a>    receitas_por_tempo,</span>
<span id="cb66-576"><a href="#cb66-576" aria-hidden="true" tabindex="-1"></a>    <span class="at">by =</span> <span class="fu">c</span>(<span class="st">'ano_eleicao'</span>, <span class="st">'cargo'</span>, <span class="st">'uf'</span>, <span class="st">'sq_candidato'</span>, <span class="st">'cpf_candidato'</span>),</span>
<span id="cb66-577"><a href="#cb66-577" aria-hidden="true" tabindex="-1"></a>    <span class="at">suffix =</span> <span class="fu">c</span>(<span class="st">""</span>, <span class="st">".y"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb66-578"><a href="#cb66-578" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span><span class="fu">ends_with</span>(<span class="st">".y"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb66-579"><a href="#cb66-579" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(</span>
<span id="cb66-580"><a href="#cb66-580" aria-hidden="true" tabindex="-1"></a>    ano_eleicao,</span>
<span id="cb66-581"><a href="#cb66-581" aria-hidden="true" tabindex="-1"></a>    uf,</span>
<span id="cb66-582"><a href="#cb66-582" aria-hidden="true" tabindex="-1"></a>    cargo, </span>
<span id="cb66-583"><a href="#cb66-583" aria-hidden="true" tabindex="-1"></a>    partido,</span>
<span id="cb66-584"><a href="#cb66-584" aria-hidden="true" tabindex="-1"></a>    sq_candidato,</span>
<span id="cb66-585"><a href="#cb66-585" aria-hidden="true" tabindex="-1"></a>    cpf_candidato, </span>
<span id="cb66-586"><a href="#cb66-586" aria-hidden="true" tabindex="-1"></a>    genero, </span>
<span id="cb66-587"><a href="#cb66-587" aria-hidden="true" tabindex="-1"></a>    cor_raca, </span>
<span id="cb66-588"><a href="#cb66-588" aria-hidden="true" tabindex="-1"></a>    eleito,</span>
<span id="cb66-589"><a href="#cb66-589" aria-hidden="true" tabindex="-1"></a>    reeleicao,</span>
<span id="cb66-590"><a href="#cb66-590" aria-hidden="true" tabindex="-1"></a>    fonte_receita,</span>
<span id="cb66-591"><a href="#cb66-591" aria-hidden="true" tabindex="-1"></a>    data_receita,</span>
<span id="cb66-592"><a href="#cb66-592" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita,</span>
<span id="cb66-593"><a href="#cb66-593" aria-hidden="true" tabindex="-1"></a>    especie_receita,</span>
<span id="cb66-594"><a href="#cb66-594" aria-hidden="true" tabindex="-1"></a>    total_receita_especie</span>
<span id="cb66-595"><a href="#cb66-595" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">%&gt;%</span></span>
<span id="cb66-596"><a href="#cb66-596" aria-hidden="true" tabindex="-1"></a>  <span class="fu">na.omit</span>()</span>
<span id="cb66-597"><a href="#cb66-597" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-598"><a href="#cb66-598" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-599"><a href="#cb66-599" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas_candidatos_por_tempo)`</span> lines generated.</span>
<span id="cb66-600"><a href="#cb66-600" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-601"><a href="#cb66-601" aria-hidden="true" tabindex="-1"></a><span class="fu">#### Step 2 - Selects and aggregates public revenue data by gender and race</span></span>
<span id="cb66-602"><a href="#cb66-602" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-603"><a href="#cb66-603" aria-hidden="true" tabindex="-1"></a>In this step, we aggregate public revenue data from both the 2018 and 2020 General Elections by gender and race.</span>
<span id="cb66-604"><a href="#cb66-604" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-607"><a href="#cb66-607" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-608"><a href="#cb66-608" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-609"><a href="#cb66-609" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-610"><a href="#cb66-610" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: public-revenue-by-gender-and-race</span></span>
<span id="cb66-611"><a href="#cb66-611" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-612"><a href="#cb66-612" aria-hidden="true" tabindex="-1"></a><span class="co"># applies monetary correction factor: 2018-october =&gt; 2022-october</span></span>
<span id="cb66-613"><a href="#cb66-613" aria-hidden="true" tabindex="-1"></a>fator_correcao <span class="ot">&lt;-</span> <span class="fl">1.63171680</span></span>
<span id="cb66-614"><a href="#cb66-614" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-615"><a href="#cb66-615" aria-hidden="true" tabindex="-1"></a>receitas_publicas <span class="ot">&lt;-</span> receitas_candidatos_por_tempo <span class="sc">%&gt;%</span></span>
<span id="cb66-616"><a href="#cb66-616" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb66-617"><a href="#cb66-617" aria-hidden="true" tabindex="-1"></a>    ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>), </span>
<span id="cb66-618"><a href="#cb66-618" aria-hidden="true" tabindex="-1"></a>    cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO DISTRITAL'</span>, </span>
<span id="cb66-619"><a href="#cb66-619" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO ESTADUAL'</span>, </span>
<span id="cb66-620"><a href="#cb66-620" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO FEDERAL'</span>),</span>
<span id="cb66-621"><a href="#cb66-621" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'FEFC'</span>, <span class="st">'FP'</span>),</span>
<span id="cb66-622"><a href="#cb66-622" aria-hidden="true" tabindex="-1"></a>    total_receita_especie <span class="sc">&lt;</span> <span class="fl">20000002.89</span>) <span class="sc">%&gt;%</span> <span class="co"># exclui entrada outlier</span></span>
<span id="cb66-623"><a href="#cb66-623" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-624"><a href="#cb66-624" aria-hidden="true" tabindex="-1"></a>    <span class="at">receita =</span> <span class="fu">ifelse</span>(</span>
<span id="cb66-625"><a href="#cb66-625" aria-hidden="true" tabindex="-1"></a>      ano_eleicao <span class="sc">==</span> <span class="dv">2018</span>, </span>
<span id="cb66-626"><a href="#cb66-626" aria-hidden="true" tabindex="-1"></a>      total_receita_especie <span class="sc">*</span> fator_correcao, </span>
<span id="cb66-627"><a href="#cb66-627" aria-hidden="true" tabindex="-1"></a>      total_receita_especie)) <span class="sc">%&gt;%</span></span>
<span id="cb66-628"><a href="#cb66-628" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(</span>
<span id="cb66-629"><a href="#cb66-629" aria-hidden="true" tabindex="-1"></a>    ano_eleicao,</span>
<span id="cb66-630"><a href="#cb66-630" aria-hidden="true" tabindex="-1"></a>    uf,</span>
<span id="cb66-631"><a href="#cb66-631" aria-hidden="true" tabindex="-1"></a>    genero,</span>
<span id="cb66-632"><a href="#cb66-632" aria-hidden="true" tabindex="-1"></a>    cor_raca,</span>
<span id="cb66-633"><a href="#cb66-633" aria-hidden="true" tabindex="-1"></a>    eleito,</span>
<span id="cb66-634"><a href="#cb66-634" aria-hidden="true" tabindex="-1"></a>    cargo,</span>
<span id="cb66-635"><a href="#cb66-635" aria-hidden="true" tabindex="-1"></a>    reeleicao,</span>
<span id="cb66-636"><a href="#cb66-636" aria-hidden="true" tabindex="-1"></a>    partido,</span>
<span id="cb66-637"><a href="#cb66-637" aria-hidden="true" tabindex="-1"></a>    cpf_candidato,</span>
<span id="cb66-638"><a href="#cb66-638" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita) <span class="sc">%&gt;%</span></span>
<span id="cb66-639"><a href="#cb66-639" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(</span>
<span id="cb66-640"><a href="#cb66-640" aria-hidden="true" tabindex="-1"></a>    <span class="at">rec_cand =</span> <span class="fu">sum</span>(total_receita_especie), </span>
<span id="cb66-641"><a href="#cb66-641" aria-hidden="true" tabindex="-1"></a>    <span class="at">na.rm =</span> <span class="cn">TRUE</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-642"><a href="#cb66-642" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(ano_eleicao, cargo, uf, genero, cor_raca)</span>
<span id="cb66-643"><a href="#cb66-643" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-644"><a href="#cb66-644" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-645"><a href="#cb66-645" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas_publicas)`</span> lines generated.</span>
<span id="cb66-646"><a href="#cb66-646" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-647"><a href="#cb66-647" aria-hidden="true" tabindex="-1"></a><span class="fu">#### Step 3 - Selects and aggregates public revenue data by source and week</span></span>
<span id="cb66-648"><a href="#cb66-648" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-649"><a href="#cb66-649" aria-hidden="true" tabindex="-1"></a>In this step, we aggregate public revenue data from both the 2018 and 2020 General Elections by source and week.</span>
<span id="cb66-650"><a href="#cb66-650" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-653"><a href="#cb66-653" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-654"><a href="#cb66-654" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-655"><a href="#cb66-655" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-656"><a href="#cb66-656" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: public-revenue-by-source-and-week</span></span>
<span id="cb66-657"><a href="#cb66-657" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-658"><a href="#cb66-658" aria-hidden="true" tabindex="-1"></a>receitas_publicas_semana <span class="ot">&lt;-</span> receitas_candidatos_por_tempo <span class="sc">%&gt;%</span></span>
<span id="cb66-659"><a href="#cb66-659" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb66-660"><a href="#cb66-660" aria-hidden="true" tabindex="-1"></a>    ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>), </span>
<span id="cb66-661"><a href="#cb66-661" aria-hidden="true" tabindex="-1"></a>    cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO DISTRITAL'</span>, </span>
<span id="cb66-662"><a href="#cb66-662" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO ESTADUAL'</span>, </span>
<span id="cb66-663"><a href="#cb66-663" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO FEDERAL'</span>),</span>
<span id="cb66-664"><a href="#cb66-664" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'FEFC'</span>, <span class="st">'FP'</span>),</span>
<span id="cb66-665"><a href="#cb66-665" aria-hidden="true" tabindex="-1"></a>    total_receita_especie <span class="sc">&lt;</span> <span class="fl">20000002.89</span>) <span class="sc">%&gt;%</span> <span class="co"># exclui entrada outlier</span></span>
<span id="cb66-666"><a href="#cb66-666" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-667"><a href="#cb66-667" aria-hidden="true" tabindex="-1"></a>    <span class="at">receita =</span> <span class="fu">ifelse</span>(</span>
<span id="cb66-668"><a href="#cb66-668" aria-hidden="true" tabindex="-1"></a>      ano_eleicao <span class="sc">==</span> <span class="dv">2018</span>, </span>
<span id="cb66-669"><a href="#cb66-669" aria-hidden="true" tabindex="-1"></a>      total_receita_especie <span class="sc">*</span> fator_correcao, </span>
<span id="cb66-670"><a href="#cb66-670" aria-hidden="true" tabindex="-1"></a>      total_receita_especie),</span>
<span id="cb66-671"><a href="#cb66-671" aria-hidden="true" tabindex="-1"></a>    <span class="at">semana_receita =</span> <span class="fu">as.Date</span>(</span>
<span id="cb66-672"><a href="#cb66-672" aria-hidden="true" tabindex="-1"></a>      <span class="fu">cut</span>(data_receita, <span class="at">breaks =</span> <span class="st">'week'</span>, </span>
<span id="cb66-673"><a href="#cb66-673" aria-hidden="true" tabindex="-1"></a>          <span class="at">start.on.monday =</span> <span class="cn">FALSE</span>)),) <span class="sc">%&gt;%</span></span>
<span id="cb66-674"><a href="#cb66-674" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(</span>
<span id="cb66-675"><a href="#cb66-675" aria-hidden="true" tabindex="-1"></a>    ano_eleicao,</span>
<span id="cb66-676"><a href="#cb66-676" aria-hidden="true" tabindex="-1"></a>    uf,</span>
<span id="cb66-677"><a href="#cb66-677" aria-hidden="true" tabindex="-1"></a>    genero,</span>
<span id="cb66-678"><a href="#cb66-678" aria-hidden="true" tabindex="-1"></a>    cor_raca,</span>
<span id="cb66-679"><a href="#cb66-679" aria-hidden="true" tabindex="-1"></a>    eleito,</span>
<span id="cb66-680"><a href="#cb66-680" aria-hidden="true" tabindex="-1"></a>    cargo,</span>
<span id="cb66-681"><a href="#cb66-681" aria-hidden="true" tabindex="-1"></a>    reeleicao,</span>
<span id="cb66-682"><a href="#cb66-682" aria-hidden="true" tabindex="-1"></a>    partido,</span>
<span id="cb66-683"><a href="#cb66-683" aria-hidden="true" tabindex="-1"></a>    cpf_candidato,</span>
<span id="cb66-684"><a href="#cb66-684" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita,</span>
<span id="cb66-685"><a href="#cb66-685" aria-hidden="true" tabindex="-1"></a>    semana_receita) <span class="sc">%&gt;%</span></span>
<span id="cb66-686"><a href="#cb66-686" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">rec_cand =</span> <span class="fu">sum</span>(total_receita_especie))</span>
<span id="cb66-687"><a href="#cb66-687" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-688"><a href="#cb66-688" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-689"><a href="#cb66-689" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas_publicas_semana)`</span> lines generated.</span>
<span id="cb66-690"><a href="#cb66-690" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-691"><a href="#cb66-691" aria-hidden="true" tabindex="-1"></a><span class="fu">#### Step 4 - Filter only public revenue data and aggregate them by source, kind and week</span></span>
<span id="cb66-692"><a href="#cb66-692" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-693"><a href="#cb66-693" aria-hidden="true" tabindex="-1"></a>In this step, we aggregate public revenue data from both the 2018 and 2020 Brazilian General Elections by source and kind of campaign revenue.</span>
<span id="cb66-694"><a href="#cb66-694" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-695"><a href="#cb66-695" aria-hidden="true" tabindex="-1"></a>Candidate level data</span>
<span id="cb66-696"><a href="#cb66-696" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-699"><a href="#cb66-699" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-700"><a href="#cb66-700" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-701"><a href="#cb66-701" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-702"><a href="#cb66-702" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: public-revenue-by-source-and-kind-clevel</span></span>
<span id="cb66-703"><a href="#cb66-703" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-704"><a href="#cb66-704" aria-hidden="true" tabindex="-1"></a>receitas_publicas_especie <span class="ot">&lt;-</span> receitas_candidatos_por_tempo <span class="sc">%&gt;%</span></span>
<span id="cb66-705"><a href="#cb66-705" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb66-706"><a href="#cb66-706" aria-hidden="true" tabindex="-1"></a>    ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>), </span>
<span id="cb66-707"><a href="#cb66-707" aria-hidden="true" tabindex="-1"></a>    cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO DISTRITAL'</span>, </span>
<span id="cb66-708"><a href="#cb66-708" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO ESTADUAL'</span>, </span>
<span id="cb66-709"><a href="#cb66-709" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO FEDERAL'</span>),</span>
<span id="cb66-710"><a href="#cb66-710" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'FEFC'</span>, <span class="st">'FP'</span>),</span>
<span id="cb66-711"><a href="#cb66-711" aria-hidden="true" tabindex="-1"></a>    total_receita_especie <span class="sc">&lt;</span> <span class="fl">20000002.89</span>) <span class="sc">%&gt;%</span> <span class="co"># exclui entrada outlier</span></span>
<span id="cb66-712"><a href="#cb66-712" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-713"><a href="#cb66-713" aria-hidden="true" tabindex="-1"></a>    <span class="at">receita =</span> <span class="fu">ifelse</span>(</span>
<span id="cb66-714"><a href="#cb66-714" aria-hidden="true" tabindex="-1"></a>      ano_eleicao <span class="sc">==</span> <span class="dv">2018</span>, </span>
<span id="cb66-715"><a href="#cb66-715" aria-hidden="true" tabindex="-1"></a>      total_receita_especie <span class="sc">*</span> fator_correcao, </span>
<span id="cb66-716"><a href="#cb66-716" aria-hidden="true" tabindex="-1"></a>      total_receita_especie)) <span class="sc">%&gt;%</span></span>
<span id="cb66-717"><a href="#cb66-717" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(</span>
<span id="cb66-718"><a href="#cb66-718" aria-hidden="true" tabindex="-1"></a>    ano_eleicao,</span>
<span id="cb66-719"><a href="#cb66-719" aria-hidden="true" tabindex="-1"></a>    uf,</span>
<span id="cb66-720"><a href="#cb66-720" aria-hidden="true" tabindex="-1"></a>    genero,</span>
<span id="cb66-721"><a href="#cb66-721" aria-hidden="true" tabindex="-1"></a>    cor_raca,</span>
<span id="cb66-722"><a href="#cb66-722" aria-hidden="true" tabindex="-1"></a>    eleito,</span>
<span id="cb66-723"><a href="#cb66-723" aria-hidden="true" tabindex="-1"></a>    cargo,</span>
<span id="cb66-724"><a href="#cb66-724" aria-hidden="true" tabindex="-1"></a>    reeleicao,</span>
<span id="cb66-725"><a href="#cb66-725" aria-hidden="true" tabindex="-1"></a>    partido,</span>
<span id="cb66-726"><a href="#cb66-726" aria-hidden="true" tabindex="-1"></a>    cpf_candidato,</span>
<span id="cb66-727"><a href="#cb66-727" aria-hidden="true" tabindex="-1"></a>    tipo_fonte_receita,</span>
<span id="cb66-728"><a href="#cb66-728" aria-hidden="true" tabindex="-1"></a>    especie_receita) <span class="sc">%&gt;%</span></span>
<span id="cb66-729"><a href="#cb66-729" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">rec_cand =</span> <span class="fu">sum</span>(total_receita_especie))</span>
<span id="cb66-730"><a href="#cb66-730" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-731"><a href="#cb66-731" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-732"><a href="#cb66-732" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas_publicas_especie)`</span> lines generated.</span>
<span id="cb66-733"><a href="#cb66-733" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-734"><a href="#cb66-734" aria-hidden="true" tabindex="-1"></a>Kind of revenue level data</span>
<span id="cb66-735"><a href="#cb66-735" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-738"><a href="#cb66-738" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-739"><a href="#cb66-739" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-740"><a href="#cb66-740" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-741"><a href="#cb66-741" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: public-revenue-by-source-and-kind-klevel</span></span>
<span id="cb66-742"><a href="#cb66-742" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-743"><a href="#cb66-743" aria-hidden="true" tabindex="-1"></a><span class="co"># agrega receitas públicas por eleição, gênero, cor/raça e espécie</span></span>
<span id="cb66-744"><a href="#cb66-744" aria-hidden="true" tabindex="-1"></a>receitas_publicas_especie_agr <span class="ot">&lt;-</span> receitas_publicas_especie <span class="sc">%&gt;%</span></span>
<span id="cb66-745"><a href="#cb66-745" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">cargo =</span> <span class="fu">ifelse</span>(cargo <span class="sc">==</span> <span class="st">"DEPUTADO DISTRITAL"</span>, </span>
<span id="cb66-746"><a href="#cb66-746" aria-hidden="true" tabindex="-1"></a>                        <span class="st">"DEPUTADO ESTADUAL"</span>, </span>
<span id="cb66-747"><a href="#cb66-747" aria-hidden="true" tabindex="-1"></a>                        cargo)) <span class="sc">%&gt;%</span></span>
<span id="cb66-748"><a href="#cb66-748" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, cargo, genero, cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb66-749"><a href="#cb66-749" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_rec_ano_cargo_genero_cor =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb66-750"><a href="#cb66-750" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-751"><a href="#cb66-751" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, cargo, genero, cor_raca, especie_receita) <span class="sc">%&gt;%</span></span>
<span id="cb66-752"><a href="#cb66-752" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(</span>
<span id="cb66-753"><a href="#cb66-753" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_rec_ano_cargo_genero_cor_especie =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>), </span>
<span id="cb66-754"><a href="#cb66-754" aria-hidden="true" tabindex="-1"></a>    <span class="at">perc_rec_ano_cargo_genero_cor_especie =</span> total_rec_ano_cargo_genero_cor_especie <span class="sc">/</span> <span class="fu">max</span>(total_rec_ano_cargo_genero_cor),</span>
<span id="cb66-755"><a href="#cb66-755" aria-hidden="true" tabindex="-1"></a>    <span class="at">.groups =</span> <span class="st">"drop"</span></span>
<span id="cb66-756"><a href="#cb66-756" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">%&gt;%</span></span>
<span id="cb66-757"><a href="#cb66-757" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(ano_eleicao, cargo, genero, especie_receita, cor_raca)</span>
<span id="cb66-758"><a href="#cb66-758" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-759"><a href="#cb66-759" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-760"><a href="#cb66-760" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas_publicas_especie_agr)`</span> lines generated.</span>
<span id="cb66-761"><a href="#cb66-761" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-762"><a href="#cb66-762" aria-hidden="true" tabindex="-1"></a><span class="fu">#### Step 5 - Aggregate public revenues by election, week, gender and race - federal deputy candidates</span></span>
<span id="cb66-763"><a href="#cb66-763" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-764"><a href="#cb66-764" aria-hidden="true" tabindex="-1"></a>In this step, we aggregate public revenue data from both the 2018 and 2020 Brazilian General Elections by year of election, week, gender and race, for federal deputy candidates.</span>
<span id="cb66-765"><a href="#cb66-765" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-768"><a href="#cb66-768" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-769"><a href="#cb66-769" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-770"><a href="#cb66-770" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-771"><a href="#cb66-771" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: public-revenue-by-week-federal-deputy</span></span>
<span id="cb66-772"><a href="#cb66-772" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-773"><a href="#cb66-773" aria-hidden="true" tabindex="-1"></a>receitas_publicas_semana_dep_fed <span class="ot">&lt;-</span> receitas_publicas_semana <span class="sc">%&gt;%</span></span>
<span id="cb66-774"><a href="#cb66-774" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(cargo <span class="sc">==</span> <span class="st">'DEPUTADO FEDERAL'</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-775"><a href="#cb66-775" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao) <span class="sc">%&gt;%</span></span>
<span id="cb66-776"><a href="#cb66-776" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_cand_ano =</span> <span class="fu">n_distinct</span>(cpf_candidato)) <span class="sc">%&gt;%</span></span>
<span id="cb66-777"><a href="#cb66-777" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-778"><a href="#cb66-778" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, genero, cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb66-779"><a href="#cb66-779" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_cand_cor =</span> <span class="fu">n_distinct</span>(cpf_candidato)) <span class="sc">%&gt;%</span></span>
<span id="cb66-780"><a href="#cb66-780" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-781"><a href="#cb66-781" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, semana_receita) <span class="sc">%&gt;%</span></span>
<span id="cb66-782"><a href="#cb66-782" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-783"><a href="#cb66-783" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receitas_semana =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb66-784"><a href="#cb66-784" aria-hidden="true" tabindex="-1"></a>    <span class="at">media_receitas_semana =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>) <span class="sc">/</span> total_cand_ano) <span class="sc">%&gt;%</span></span>
<span id="cb66-785"><a href="#cb66-785" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-786"><a href="#cb66-786" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, semana_receita, genero, cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb66-787"><a href="#cb66-787" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-788"><a href="#cb66-788" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receitas_cor =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb66-789"><a href="#cb66-789" aria-hidden="true" tabindex="-1"></a>    <span class="at">media_receitas_genero_cor =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>) <span class="sc">/</span> total_cand_cor) <span class="sc">%&gt;%</span></span>
<span id="cb66-790"><a href="#cb66-790" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-791"><a href="#cb66-791" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(ano_eleicao, semana_receita, genero, cor_raca)</span>
<span id="cb66-792"><a href="#cb66-792" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-793"><a href="#cb66-793" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-794"><a href="#cb66-794" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas_publicas_semana_dep_fed)`</span> lines generated (federal deputy).</span>
<span id="cb66-795"><a href="#cb66-795" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-796"><a href="#cb66-796" aria-hidden="true" tabindex="-1"></a><span class="fu">#### Step 6 - Aggregate public revenues per week - state deputy candidates</span></span>
<span id="cb66-797"><a href="#cb66-797" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-798"><a href="#cb66-798" aria-hidden="true" tabindex="-1"></a>In this step, we aggregate public revenue data from both the 2018 and 2020 Brazilian General Elections by year of election, week, gender and race, for state deputy candidates.</span>
<span id="cb66-799"><a href="#cb66-799" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-802"><a href="#cb66-802" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-803"><a href="#cb66-803" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-804"><a href="#cb66-804" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-805"><a href="#cb66-805" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: public-revenue-by-week-state-deputy</span></span>
<span id="cb66-806"><a href="#cb66-806" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-807"><a href="#cb66-807" aria-hidden="true" tabindex="-1"></a><span class="co"># agrega receitas públicas por eleição, semana, gênero, cor/raça e situaçao de reeleição</span></span>
<span id="cb66-808"><a href="#cb66-808" aria-hidden="true" tabindex="-1"></a>receitas_publicas_semana_dep_est <span class="ot">&lt;-</span> receitas_publicas_semana <span class="sc">%&gt;%</span></span>
<span id="cb66-809"><a href="#cb66-809" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO DISTRITAL'</span>, <span class="st">'DEPUTADO ESTADUAL'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb66-810"><a href="#cb66-810" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao) <span class="sc">%&gt;%</span></span>
<span id="cb66-811"><a href="#cb66-811" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_cand_ano =</span> <span class="fu">n_distinct</span>(cpf_candidato)) <span class="sc">%&gt;%</span></span>
<span id="cb66-812"><a href="#cb66-812" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-813"><a href="#cb66-813" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, genero, cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb66-814"><a href="#cb66-814" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_cand_cor =</span> <span class="fu">n_distinct</span>(cpf_candidato)) <span class="sc">%&gt;%</span></span>
<span id="cb66-815"><a href="#cb66-815" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-816"><a href="#cb66-816" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, semana_receita) <span class="sc">%&gt;%</span></span>
<span id="cb66-817"><a href="#cb66-817" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-818"><a href="#cb66-818" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receitas_semana =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb66-819"><a href="#cb66-819" aria-hidden="true" tabindex="-1"></a>    <span class="at">media_receitas_semana =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>) <span class="sc">/</span> total_cand_ano) <span class="sc">%&gt;%</span></span>
<span id="cb66-820"><a href="#cb66-820" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-821"><a href="#cb66-821" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ano_eleicao, semana_receita, genero, cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb66-822"><a href="#cb66-822" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-823"><a href="#cb66-823" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receitas_cor =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb66-824"><a href="#cb66-824" aria-hidden="true" tabindex="-1"></a>    <span class="at">media_receitas_genero_cor =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>) <span class="sc">/</span> total_cand_cor) <span class="sc">%&gt;%</span></span>
<span id="cb66-825"><a href="#cb66-825" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-826"><a href="#cb66-826" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(ano_eleicao, semana_receita, genero, cor_raca)</span>
<span id="cb66-827"><a href="#cb66-827" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-828"><a href="#cb66-828" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-829"><a href="#cb66-829" aria-hidden="true" tabindex="-1"></a>⟶ <span class="in">`{r} nrow(receitas_publicas_semana_dep_est)`</span> lines generated (state deputy).</span>
<span id="cb66-830"><a href="#cb66-830" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-831"><a href="#cb66-831" aria-hidden="true" tabindex="-1"></a><span class="fu">#### Step 7 - Calculate minimum and maximum values of public revenue</span></span>
<span id="cb66-832"><a href="#cb66-832" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-833"><a href="#cb66-833" aria-hidden="true" tabindex="-1"></a>In this step, we identify both the minimum and maximum values of public revenue values and the minimum and maximum dates for constructing the graph scales.</span>
<span id="cb66-834"><a href="#cb66-834" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-837"><a href="#cb66-837" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-838"><a href="#cb66-838" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-839"><a href="#cb66-839" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-840"><a href="#cb66-840" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: max-public-revenue</span></span>
<span id="cb66-841"><a href="#cb66-841" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-842"><a href="#cb66-842" aria-hidden="true" tabindex="-1"></a>sum_receitas <span class="ot">&lt;-</span> <span class="fu">aggregate</span>(</span>
<span id="cb66-843"><a href="#cb66-843" aria-hidden="true" tabindex="-1"></a>  rec_cand <span class="sc">~</span> ano_eleicao <span class="sc">+</span> genero <span class="sc">+</span> semana_receita, </span>
<span id="cb66-844"><a href="#cb66-844" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> receitas_publicas_semana, sum)</span>
<span id="cb66-845"><a href="#cb66-845" aria-hidden="true" tabindex="-1"></a>sum_receitas <span class="ot">&lt;-</span> <span class="fu">tibble</span>(sum_receitas) <span class="sc">%&gt;%</span></span>
<span id="cb66-846"><a href="#cb66-846" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(ano_eleicao, genero, semana_receita)</span>
<span id="cb66-847"><a href="#cb66-847" aria-hidden="true" tabindex="-1"></a>max_receita <span class="ot">&lt;-</span> <span class="fu">max</span>(sum_receitas<span class="sc">$</span>rec_cand)</span>
<span id="cb66-848"><a href="#cb66-848" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-849"><a href="#cb66-849" aria-hidden="true" tabindex="-1"></a><span class="co"># foram usadas as datas da convenção partidária</span></span>
<span id="cb66-850"><a href="#cb66-850" aria-hidden="true" tabindex="-1"></a>min_data_convencao_2018 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"2018-07-20"</span>, <span class="st">"2018-10-06"</span>)</span>
<span id="cb66-851"><a href="#cb66-851" aria-hidden="true" tabindex="-1"></a>min_data_convencao_2022 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"2022-07-20"</span>, <span class="st">"2022-10-01"</span>)</span>
<span id="cb66-852"><a href="#cb66-852" aria-hidden="true" tabindex="-1"></a>min_data_campanha_2018 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"2018-08-13"</span>, <span class="st">"2018-10-06"</span>)</span>
<span id="cb66-853"><a href="#cb66-853" aria-hidden="true" tabindex="-1"></a>min_data_campanha_2022 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"2022-08-16"</span>, <span class="st">"2022-10-01"</span>)</span>
<span id="cb66-854"><a href="#cb66-854" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-855"><a href="#cb66-855" aria-hidden="true" tabindex="-1"></a><span class="co"># funçao para gravar uma figura em alta resoluçao</span></span>
<span id="cb66-856"><a href="#cb66-856" aria-hidden="true" tabindex="-1"></a>grava_figura <span class="ot">&lt;-</span> <span class="cf">function</span>(nome, formato) {</span>
<span id="cb66-857"><a href="#cb66-857" aria-hidden="true" tabindex="-1"></a>  Cairo<span class="sc">::</span><span class="fu">Cairo</span>(</span>
<span id="cb66-858"><a href="#cb66-858" aria-hidden="true" tabindex="-1"></a>    <span class="dv">30</span>,</span>
<span id="cb66-859"><a href="#cb66-859" aria-hidden="true" tabindex="-1"></a>    <span class="dv">20</span>,</span>
<span id="cb66-860"><a href="#cb66-860" aria-hidden="true" tabindex="-1"></a>    <span class="at">file =</span> <span class="fu">paste</span>(nome, formato, <span class="at">sep =</span> <span class="st">"."</span>),</span>
<span id="cb66-861"><a href="#cb66-861" aria-hidden="true" tabindex="-1"></a>    <span class="at">type =</span> formato,</span>
<span id="cb66-862"><a href="#cb66-862" aria-hidden="true" tabindex="-1"></a>    <span class="at">bg =</span> <span class="st">"transparent"</span>,</span>
<span id="cb66-863"><a href="#cb66-863" aria-hidden="true" tabindex="-1"></a>    <span class="at">dpi =</span> <span class="dv">600</span>,</span>
<span id="cb66-864"><a href="#cb66-864" aria-hidden="true" tabindex="-1"></a>    <span class="at">units =</span> <span class="st">"cm"</span></span>
<span id="cb66-865"><a href="#cb66-865" aria-hidden="true" tabindex="-1"></a>  )  </span>
<span id="cb66-866"><a href="#cb66-866" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb66-867"><a href="#cb66-867" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-868"><a href="#cb66-868" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-869"><a href="#cb66-869" aria-hidden="true" tabindex="-1"></a><span class="ss">-   </span>Maximum public revenue value for a single week = <span class="in">`{r} max_receita`</span></span>
<span id="cb66-870"><a href="#cb66-870" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-871"><a href="#cb66-871" aria-hidden="true" tabindex="-1"></a><span class="ss">-   </span>Convention date for 2018 Election = <span class="in">`{r} min_data_convencao_2018`</span></span>
<span id="cb66-872"><a href="#cb66-872" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-873"><a href="#cb66-873" aria-hidden="true" tabindex="-1"></a><span class="ss">-   </span>Convention date for 2022 Election = <span class="in">`{r} min_data_convencao_2022`</span></span>
<span id="cb66-874"><a href="#cb66-874" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-875"><a href="#cb66-875" aria-hidden="true" tabindex="-1"></a><span class="fu"># Data Analysis</span></span>
<span id="cb66-876"><a href="#cb66-876" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-877"><a href="#cb66-877" aria-hidden="true" tabindex="-1"></a><span class="fu">## Preliminary Analysis - total resources transfers between candidate providers, by resource type</span></span>
<span id="cb66-878"><a href="#cb66-878" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-881"><a href="#cb66-881" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-882"><a href="#cb66-882" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-883"><a href="#cb66-883" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-884"><a href="#cb66-884" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: total-resource-transfers-candidate-providers-by-resource-type</span></span>
<span id="cb66-885"><a href="#cb66-885" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-886"><a href="#cb66-886" aria-hidden="true" tabindex="-1"></a>receitas <span class="sc">%&gt;%</span></span>
<span id="cb66-887"><a href="#cb66-887" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2022</span>,</span>
<span id="cb66-888"><a href="#cb66-888" aria-hidden="true" tabindex="-1"></a>         NR_CPF_CNPJ_DOADOR <span class="sc">!=</span> NR_CNPJ_PRESTADOR_CONTA,</span>
<span id="cb66-889"><a href="#cb66-889" aria-hidden="true" tabindex="-1"></a>         DS_FONTE_RECURSO <span class="sc">%in%</span> </span>
<span id="cb66-890"><a href="#cb66-890" aria-hidden="true" tabindex="-1"></a>           <span class="fu">c</span>(<span class="st">'Recursos de outros candidatos'</span>, </span>
<span id="cb66-891"><a href="#cb66-891" aria-hidden="true" tabindex="-1"></a>             <span class="st">'Recursos de partido político'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb66-892"><a href="#cb66-892" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(tipo_recurso) <span class="sc">%&gt;%</span></span>
<span id="cb66-893"><a href="#cb66-893" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">transferencias_entre_prestadores =</span> <span class="fu">sum</span>(TOTAL_RECEITA),</span>
<span id="cb66-894"><a href="#cb66-894" aria-hidden="true" tabindex="-1"></a>            <span class="at">.groups =</span> <span class="st">'drop'</span>)</span>
<span id="cb66-895"><a href="#cb66-895" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-896"><a href="#cb66-896" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-897"><a href="#cb66-897" aria-hidden="true" tabindex="-1"></a><span class="fu">## **Distribution of Cash-Equivalent and Cash Funding**</span></span>
<span id="cb66-898"><a href="#cb66-898" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-899"><a href="#cb66-899" aria-hidden="true" tabindex="-1"></a>::: callout-note</span>
<span id="cb66-900"><a href="#cb66-900" aria-hidden="true" tabindex="-1"></a>In this work, we consider only funding originating from public revenue.</span>
<span id="cb66-901"><a href="#cb66-901" aria-hidden="true" tabindex="-1"></a>:::</span>
<span id="cb66-902"><a href="#cb66-902" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-903"><a href="#cb66-903" aria-hidden="true" tabindex="-1"></a><span class="fu">### Graph 1 - Proportion of cash-equivalent funds of candidates for federal deputy, by race and gender</span></span>
<span id="cb66-904"><a href="#cb66-904" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-905"><a href="#cb66-905" aria-hidden="true" tabindex="-1"></a>Create data object</span>
<span id="cb66-906"><a href="#cb66-906" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-909"><a href="#cb66-909" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-910"><a href="#cb66-910" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-911"><a href="#cb66-911" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-912"><a href="#cb66-912" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: create-g1-data</span></span>
<span id="cb66-913"><a href="#cb66-913" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-914"><a href="#cb66-914" aria-hidden="true" tabindex="-1"></a>g1_data <span class="ot">&lt;-</span> receitas_publicas_especie_agr <span class="sc">%&gt;%</span> </span>
<span id="cb66-915"><a href="#cb66-915" aria-hidden="true" tabindex="-1"></a>    <span class="fu">filter</span>(</span>
<span id="cb66-916"><a href="#cb66-916" aria-hidden="true" tabindex="-1"></a>      ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>),</span>
<span id="cb66-917"><a href="#cb66-917" aria-hidden="true" tabindex="-1"></a>      cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>),</span>
<span id="cb66-918"><a href="#cb66-918" aria-hidden="true" tabindex="-1"></a>      cargo <span class="sc">==</span> <span class="st">'DEPUTADO FEDERAL'</span>,</span>
<span id="cb66-919"><a href="#cb66-919" aria-hidden="true" tabindex="-1"></a>      especie_receita <span class="sc">==</span> <span class="st">'Cash-equivalent'</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-920"><a href="#cb66-920" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(</span>
<span id="cb66-921"><a href="#cb66-921" aria-hidden="true" tabindex="-1"></a>      <span class="at">ano_eleicao =</span> <span class="fu">as.factor</span>(ano_eleicao),</span>
<span id="cb66-922"><a href="#cb66-922" aria-hidden="true" tabindex="-1"></a>      <span class="at">cor_raca =</span> <span class="fu">factor</span>(cor_raca, <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>))</span>
<span id="cb66-923"><a href="#cb66-923" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb66-924"><a href="#cb66-924" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-925"><a href="#cb66-925" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-926"><a href="#cb66-926" aria-hidden="true" tabindex="-1"></a>Plot figure</span>
<span id="cb66-927"><a href="#cb66-927" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-930"><a href="#cb66-930" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-931"><a href="#cb66-931" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-932"><a href="#cb66-932" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-933"><a href="#cb66-933" aria-hidden="true" tabindex="-1"></a><span class="co">#| class: output</span></span>
<span id="cb66-934"><a href="#cb66-934" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: fig-1</span></span>
<span id="cb66-935"><a href="#cb66-935" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-cap: "Proportion of cash-equivalent funding of candidates to federal deputy, in 2018 and 2022, by gender and race"</span></span>
<span id="cb66-936"><a href="#cb66-936" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-alt: "Proportion of cash-equivalent funding of candidates to federal deputy, in 2018 and 2022, by gender and race"</span></span>
<span id="cb66-937"><a href="#cb66-937" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-width: 8</span></span>
<span id="cb66-938"><a href="#cb66-938" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-height: 6</span></span>
<span id="cb66-939"><a href="#cb66-939" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-940"><a href="#cb66-940" aria-hidden="true" tabindex="-1"></a><span class="co"># identifies the minimum and maximum revenue, as well as the minimum and maximum dates to build the chart scale</span></span>
<span id="cb66-941"><a href="#cb66-941" aria-hidden="true" tabindex="-1"></a>max_receita <span class="ot">&lt;-</span> <span class="fu">max</span>(g1_data<span class="sc">$</span>perc_rec_ano_cargo_genero_cor_especie)</span>
<span id="cb66-942"><a href="#cb66-942" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-943"><a href="#cb66-943" aria-hidden="true" tabindex="-1"></a><span class="co">#limites &lt;- c(0, max_receita) * 2</span></span>
<span id="cb66-944"><a href="#cb66-944" aria-hidden="true" tabindex="-1"></a><span class="co">#quebras &lt;- round(seq(limites[1], limites[2], by = max_receita / 10), </span></span>
<span id="cb66-945"><a href="#cb66-945" aria-hidden="true" tabindex="-1"></a><span class="co">#                 digits = 2)</span></span>
<span id="cb66-946"><a href="#cb66-946" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-947"><a href="#cb66-947" aria-hidden="true" tabindex="-1"></a><span class="co"># 2018 and 2022</span></span>
<span id="cb66-948"><a href="#cb66-948" aria-hidden="true" tabindex="-1"></a>g1_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb66-949"><a href="#cb66-949" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g1_data, </span>
<span id="cb66-950"><a href="#cb66-950" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(<span class="at">fill =</span> genero, </span>
<span id="cb66-951"><a href="#cb66-951" aria-hidden="true" tabindex="-1"></a>      <span class="at">x =</span> <span class="fu">as.factor</span>(cor_raca), </span>
<span id="cb66-952"><a href="#cb66-952" aria-hidden="true" tabindex="-1"></a>      <span class="at">y =</span> perc_rec_ano_cargo_genero_cor_especie)) <span class="sc">+</span></span>
<span id="cb66-953"><a href="#cb66-953" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb66-954"><a href="#cb66-954" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb66-955"><a href="#cb66-955" aria-hidden="true" tabindex="-1"></a>    <span class="fu">aes</span>(<span class="at">label=</span>scales<span class="sc">:::</span><span class="fu">percent</span>(perc_rec_ano_cargo_genero_cor_especie, <span class="at">accuracy=</span><span class="fl">0.1</span>)), <span class="at">position=</span><span class="fu">position_dodge</span>(<span class="at">width =</span> <span class="fl">0.9</span>), </span>
<span id="cb66-956"><a href="#cb66-956" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust=</span> <span class="sc">-</span><span class="fl">0.5</span>, </span>
<span id="cb66-957"><a href="#cb66-957" aria-hidden="true" tabindex="-1"></a>    <span class="at">size=</span> <span class="dv">4</span></span>
<span id="cb66-958"><a href="#cb66-958" aria-hidden="true" tabindex="-1"></a>    )<span class="sc">+</span></span>
<span id="cb66-959"><a href="#cb66-959" aria-hidden="true" tabindex="-1"></a>  <span class="fu">facet_wrap</span>(<span class="sc">~</span>ano_eleicao) <span class="sc">+</span></span>
<span id="cb66-960"><a href="#cb66-960" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb66-961"><a href="#cb66-961" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_fill_brewer</span>(<span class="at">palette =</span> <span class="st">"Set1"</span>) <span class="sc">+</span></span>
<span id="cb66-962"><a href="#cb66-962" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb66-963"><a href="#cb66-963" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span>percent,</span>
<span id="cb66-964"><a href="#cb66-964" aria-hidden="true" tabindex="-1"></a>   <span class="co"># limits = limites,</span></span>
<span id="cb66-965"><a href="#cb66-965" aria-hidden="true" tabindex="-1"></a>  <span class="co">#  breaks = quebras) +</span></span>
<span id="cb66-966"><a href="#cb66-966" aria-hidden="true" tabindex="-1"></a>     <span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="fl">0.10</span>), <span class="co">#0% a 10%</span></span>
<span id="cb66-967"><a href="#cb66-967" aria-hidden="true" tabindex="-1"></a>      <span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="fl">0.10</span>, <span class="at">by =</span> <span class="fl">0.02</span>)) <span class="sc">+</span></span>
<span id="cb66-968"><a href="#cb66-968" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-969"><a href="#cb66-969" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb66-970"><a href="#cb66-970" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Race/color"</span>, </span>
<span id="cb66-971"><a href="#cb66-971" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Proportion of cash-equivalent funding (%)"</span>) <span class="sc">+</span></span>
<span id="cb66-972"><a href="#cb66-972" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb66-973"><a href="#cb66-973" aria-hidden="true" tabindex="-1"></a>  <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-974"><a href="#cb66-974" aria-hidden="true" tabindex="-1"></a>    <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-975"><a href="#cb66-975" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">14</span>), </span>
<span id="cb66-976"><a href="#cb66-976" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">14</span>), </span>
<span id="cb66-977"><a href="#cb66-977" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>), </span>
<span id="cb66-978"><a href="#cb66-978" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>), </span>
<span id="cb66-979"><a href="#cb66-979" aria-hidden="true" tabindex="-1"></a>    <span class="at">strip.text =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>),    </span>
<span id="cb66-980"><a href="#cb66-980" aria-hidden="true" tabindex="-1"></a>    <span class="at">legend.title =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb66-981"><a href="#cb66-981" aria-hidden="true" tabindex="-1"></a>    <span class="at">legend.text =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>)) </span>
<span id="cb66-982"><a href="#cb66-982" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-983"><a href="#cb66-983" aria-hidden="true" tabindex="-1"></a>g1_figure</span>
<span id="cb66-984"><a href="#cb66-984" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-985"><a href="#cb66-985" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-986"><a href="#cb66-986" aria-hidden="true" tabindex="-1"></a>Save figure</span>
<span id="cb66-987"><a href="#cb66-987" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-990"><a href="#cb66-990" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-991"><a href="#cb66-991" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-992"><a href="#cb66-992" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-993"><a href="#cb66-993" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-fig-1</span></span>
<span id="cb66-994"><a href="#cb66-994" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-995"><a href="#cb66-995" aria-hidden="true" tabindex="-1"></a><span class="fu">grava_figura</span>(<span class="st">"..//Figuras//paper-fig-1"</span>, <span class="st">"png"</span>)</span>
<span id="cb66-996"><a href="#cb66-996" aria-hidden="true" tabindex="-1"></a>g1_figure</span>
<span id="cb66-997"><a href="#cb66-997" aria-hidden="true" tabindex="-1"></a><span class="fu">dev.off</span>()</span>
<span id="cb66-998"><a href="#cb66-998" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-999"><a href="#cb66-999" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1000"><a href="#cb66-1000" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1001"><a href="#cb66-1001" aria-hidden="true" tabindex="-1"></a><span class="fu">### Graph 2 - Proportion of cash-equivalent funds of candidates for state deputy, by race and gender</span></span>
<span id="cb66-1002"><a href="#cb66-1002" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1003"><a href="#cb66-1003" aria-hidden="true" tabindex="-1"></a>Create data object</span>
<span id="cb66-1004"><a href="#cb66-1004" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1007"><a href="#cb66-1007" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1008"><a href="#cb66-1008" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1009"><a href="#cb66-1009" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1010"><a href="#cb66-1010" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: create-g2-data</span></span>
<span id="cb66-1011"><a href="#cb66-1011" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1012"><a href="#cb66-1012" aria-hidden="true" tabindex="-1"></a>g2_data <span class="ot">&lt;-</span> receitas_publicas_especie_agr <span class="sc">%&gt;%</span> </span>
<span id="cb66-1013"><a href="#cb66-1013" aria-hidden="true" tabindex="-1"></a>    <span class="fu">filter</span>(</span>
<span id="cb66-1014"><a href="#cb66-1014" aria-hidden="true" tabindex="-1"></a>      ano_eleicao <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">2018</span>, <span class="dv">2022</span>),</span>
<span id="cb66-1015"><a href="#cb66-1015" aria-hidden="true" tabindex="-1"></a>      cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>),</span>
<span id="cb66-1016"><a href="#cb66-1016" aria-hidden="true" tabindex="-1"></a>      cargo <span class="sc">==</span> <span class="st">"DEPUTADO ESTADUAL"</span>,</span>
<span id="cb66-1017"><a href="#cb66-1017" aria-hidden="true" tabindex="-1"></a>      especie_receita <span class="sc">==</span> <span class="st">"Cash-equivalent"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-1018"><a href="#cb66-1018" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-1019"><a href="#cb66-1019" aria-hidden="true" tabindex="-1"></a>    <span class="at">ano_eleicao =</span> <span class="fu">as.factor</span>(ano_eleicao),</span>
<span id="cb66-1020"><a href="#cb66-1020" aria-hidden="true" tabindex="-1"></a>    <span class="at">cor_raca =</span> <span class="fu">factor</span>(cor_raca, <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>))</span>
<span id="cb66-1021"><a href="#cb66-1021" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb66-1022"><a href="#cb66-1022" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1023"><a href="#cb66-1023" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1024"><a href="#cb66-1024" aria-hidden="true" tabindex="-1"></a>Plot figure</span>
<span id="cb66-1025"><a href="#cb66-1025" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1028"><a href="#cb66-1028" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1029"><a href="#cb66-1029" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1030"><a href="#cb66-1030" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1031"><a href="#cb66-1031" aria-hidden="true" tabindex="-1"></a><span class="co">#| class: output</span></span>
<span id="cb66-1032"><a href="#cb66-1032" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: fig-2</span></span>
<span id="cb66-1033"><a href="#cb66-1033" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-cap: "Proportion of cash-equivalent funding of candidates to state deputy, in 2018 and 2022, by gender and race"</span></span>
<span id="cb66-1034"><a href="#cb66-1034" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-alt: "Proportion of cash-equivalent funding of candidates to state deputy, in 2018 and 2022, by gender and race"</span></span>
<span id="cb66-1035"><a href="#cb66-1035" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-width: 8</span></span>
<span id="cb66-1036"><a href="#cb66-1036" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-height: 6</span></span>
<span id="cb66-1037"><a href="#cb66-1037" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1038"><a href="#cb66-1038" aria-hidden="true" tabindex="-1"></a><span class="co"># identifies the minimum and maximum revenue, as well as the minimum and maximum dates to build the chart scale</span></span>
<span id="cb66-1039"><a href="#cb66-1039" aria-hidden="true" tabindex="-1"></a>max_receita <span class="ot">&lt;-</span> <span class="fu">max</span>(g2_data<span class="sc">$</span>perc_rec_ano_cargo_genero_cor_especie)</span>
<span id="cb66-1040"><a href="#cb66-1040" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1041"><a href="#cb66-1041" aria-hidden="true" tabindex="-1"></a>limites <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">0</span>, max_receita) <span class="sc">*</span> <span class="fl">1.01</span></span>
<span id="cb66-1042"><a href="#cb66-1042" aria-hidden="true" tabindex="-1"></a>quebras <span class="ot">&lt;-</span> <span class="fu">seq</span>(limites[<span class="dv">1</span>], limites[<span class="dv">2</span>], <span class="at">by =</span> max_receita <span class="sc">/</span> <span class="dv">10</span>)</span>
<span id="cb66-1043"><a href="#cb66-1043" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1044"><a href="#cb66-1044" aria-hidden="true" tabindex="-1"></a><span class="co"># 2018 and 2022</span></span>
<span id="cb66-1045"><a href="#cb66-1045" aria-hidden="true" tabindex="-1"></a>g2_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb66-1046"><a href="#cb66-1046" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g2_data, </span>
<span id="cb66-1047"><a href="#cb66-1047" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(<span class="at">fill =</span> genero, </span>
<span id="cb66-1048"><a href="#cb66-1048" aria-hidden="true" tabindex="-1"></a>      <span class="at">x =</span> <span class="fu">as.factor</span>(cor_raca), </span>
<span id="cb66-1049"><a href="#cb66-1049" aria-hidden="true" tabindex="-1"></a>      <span class="at">y =</span> perc_rec_ano_cargo_genero_cor_especie)) <span class="sc">+</span></span>
<span id="cb66-1050"><a href="#cb66-1050" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb66-1051"><a href="#cb66-1051" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb66-1052"><a href="#cb66-1052" aria-hidden="true" tabindex="-1"></a>   <span class="fu">aes</span>(<span class="at">label =</span> scales<span class="sc">::</span><span class="fu">percent</span>(perc_rec_ano_cargo_genero_cor_especie, <span class="at">accuracy =</span> <span class="fl">0.1</span>)),</span>
<span id="cb66-1053"><a href="#cb66-1053" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">position_dodge</span>(<span class="at">width =</span> <span class="fl">0.9</span>),</span>
<span id="cb66-1054"><a href="#cb66-1054" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust =</span> <span class="sc">-</span><span class="fl">0.5</span>,</span>
<span id="cb66-1055"><a href="#cb66-1055" aria-hidden="true" tabindex="-1"></a>    <span class="at">size =</span> <span class="dv">4</span></span>
<span id="cb66-1056"><a href="#cb66-1056" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">+</span></span>
<span id="cb66-1057"><a href="#cb66-1057" aria-hidden="true" tabindex="-1"></a>  <span class="fu">facet_wrap</span>(<span class="sc">~</span>ano_eleicao) <span class="sc">+</span></span>
<span id="cb66-1058"><a href="#cb66-1058" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme_minimal</span>() <span class="sc">+</span></span>
<span id="cb66-1059"><a href="#cb66-1059" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_fill_brewer</span>(<span class="at">palette =</span> <span class="st">"Set1"</span>) <span class="sc">+</span></span>
<span id="cb66-1060"><a href="#cb66-1060" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb66-1061"><a href="#cb66-1061" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span>percent,</span>
<span id="cb66-1062"><a href="#cb66-1062" aria-hidden="true" tabindex="-1"></a> <span class="co">#   limits = limites,</span></span>
<span id="cb66-1063"><a href="#cb66-1063" aria-hidden="true" tabindex="-1"></a><span class="co">#    breaks = quebras) +</span></span>
<span id="cb66-1064"><a href="#cb66-1064" aria-hidden="true" tabindex="-1"></a>  <span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="fl">0.20</span>), <span class="co">#0% a 22%</span></span>
<span id="cb66-1065"><a href="#cb66-1065" aria-hidden="true" tabindex="-1"></a>    <span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="fl">0.20</span>, <span class="at">by =</span> <span class="fl">0.02</span>)) <span class="sc">+</span></span>
<span id="cb66-1066"><a href="#cb66-1066" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb66-1067"><a href="#cb66-1067" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Race/color"</span>, </span>
<span id="cb66-1068"><a href="#cb66-1068" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Proportion of cash-equivalent funding (%)"</span>) <span class="sc">+</span></span>
<span id="cb66-1069"><a href="#cb66-1069" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(</span>
<span id="cb66-1070"><a href="#cb66-1070" aria-hidden="true" tabindex="-1"></a>    <span class="co">#panel.background = element_rect(fill='transparent'),</span></span>
<span id="cb66-1071"><a href="#cb66-1071" aria-hidden="true" tabindex="-1"></a>    <span class="co">#plot.background = element_rect(fill='transparent', color=NA),</span></span>
<span id="cb66-1072"><a href="#cb66-1072" aria-hidden="true" tabindex="-1"></a>    <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-1073"><a href="#cb66-1073" aria-hidden="true" tabindex="-1"></a>    <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-1074"><a href="#cb66-1074" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">14</span>), <span class="co">#RAÇAS</span></span>
<span id="cb66-1075"><a href="#cb66-1075" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">14</span>), <span class="co"># % 0 A 100%</span></span>
<span id="cb66-1076"><a href="#cb66-1076" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>), <span class="co"># legenda horizontal</span></span>
<span id="cb66-1077"><a href="#cb66-1077" aria-hidden="true" tabindex="-1"></a>    <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>), <span class="co"># legenda vertical</span></span>
<span id="cb66-1078"><a href="#cb66-1078" aria-hidden="true" tabindex="-1"></a>    <span class="at">strip.text =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">15</span>),    </span>
<span id="cb66-1079"><a href="#cb66-1079" aria-hidden="true" tabindex="-1"></a>    <span class="at">legend.title =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb66-1080"><a href="#cb66-1080" aria-hidden="true" tabindex="-1"></a>    <span class="at">legend.text =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>))</span>
<span id="cb66-1081"><a href="#cb66-1081" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1082"><a href="#cb66-1082" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1083"><a href="#cb66-1083" aria-hidden="true" tabindex="-1"></a>g2_figure</span>
<span id="cb66-1084"><a href="#cb66-1084" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1085"><a href="#cb66-1085" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1086"><a href="#cb66-1086" aria-hidden="true" tabindex="-1"></a>Save figure</span>
<span id="cb66-1087"><a href="#cb66-1087" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1090"><a href="#cb66-1090" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1091"><a href="#cb66-1091" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1092"><a href="#cb66-1092" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1093"><a href="#cb66-1093" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-fig-2</span></span>
<span id="cb66-1094"><a href="#cb66-1094" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1095"><a href="#cb66-1095" aria-hidden="true" tabindex="-1"></a><span class="fu">grava_figura</span>(<span class="st">"..//Figuras//paper-fig-2"</span>, <span class="st">"png"</span>)</span>
<span id="cb66-1096"><a href="#cb66-1096" aria-hidden="true" tabindex="-1"></a>g2_figure</span>
<span id="cb66-1097"><a href="#cb66-1097" aria-hidden="true" tabindex="-1"></a><span class="fu">dev.off</span>()</span>
<span id="cb66-1098"><a href="#cb66-1098" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1099"><a href="#cb66-1099" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1100"><a href="#cb66-1100" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1101"><a href="#cb66-1101" aria-hidden="true" tabindex="-1"></a><span class="fu">## When the funds were transferred</span></span>
<span id="cb66-1102"><a href="#cb66-1102" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1103"><a href="#cb66-1103" aria-hidden="true" tabindex="-1"></a><span class="fu">### Graph 3 - Ratio between the group and the overall average of public funding of candidates for federal deputy by gender and race, each week</span></span>
<span id="cb66-1104"><a href="#cb66-1104" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1105"><a href="#cb66-1105" aria-hidden="true" tabindex="-1"></a>::: callout-note</span>
<span id="cb66-1106"><a href="#cb66-1106" aria-hidden="true" tabindex="-1"></a>The amount of public revenue for the week received by the group (gender, race) weighted by the number of applications is equivalent to the average public revenue for that week.</span>
<span id="cb66-1107"><a href="#cb66-1107" aria-hidden="true" tabindex="-1"></a>:::</span>
<span id="cb66-1108"><a href="#cb66-1108" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1109"><a href="#cb66-1109" aria-hidden="true" tabindex="-1"></a>Create data object</span>
<span id="cb66-1110"><a href="#cb66-1110" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1113"><a href="#cb66-1113" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1114"><a href="#cb66-1114" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1115"><a href="#cb66-1115" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1116"><a href="#cb66-1116" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: create-g3-data</span></span>
<span id="cb66-1117"><a href="#cb66-1117" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1118"><a href="#cb66-1118" aria-hidden="true" tabindex="-1"></a><span class="co"># Federal Deputy</span></span>
<span id="cb66-1119"><a href="#cb66-1119" aria-hidden="true" tabindex="-1"></a>g3_data <span class="ot">&lt;-</span>  receitas_publicas_semana_dep_fed <span class="sc">%&gt;%</span> </span>
<span id="cb66-1120"><a href="#cb66-1120" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter_at</span>(<span class="fu">vars</span>(<span class="fu">everything</span>()), <span class="fu">all_vars</span>(<span class="sc">!</span><span class="fu">is.na</span>(.))) <span class="sc">%&gt;%</span></span>
<span id="cb66-1121"><a href="#cb66-1121" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb66-1122"><a href="#cb66-1122" aria-hidden="true" tabindex="-1"></a>    genero <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"Men"</span>, <span class="st">"Women"</span>),</span>
<span id="cb66-1123"><a href="#cb66-1123" aria-hidden="true" tabindex="-1"></a>    cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'White'</span>, <span class="st">'Black'</span>))</span>
<span id="cb66-1124"><a href="#cb66-1124" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1125"><a href="#cb66-1125" aria-hidden="true" tabindex="-1"></a><span class="co"># para alterar a ordem das barras, para ficar como na versão em português</span></span>
<span id="cb66-1126"><a href="#cb66-1126" aria-hidden="true" tabindex="-1"></a>g3_data <span class="ot">&lt;-</span> g3_data <span class="sc">%&gt;%</span></span>
<span id="cb66-1127"><a href="#cb66-1127" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-1128"><a href="#cb66-1128" aria-hidden="true" tabindex="-1"></a>    <span class="at">genero_cor =</span> <span class="fu">factor</span>(</span>
<span id="cb66-1129"><a href="#cb66-1129" aria-hidden="true" tabindex="-1"></a>      <span class="fu">paste</span>(genero, cor_raca, <span class="at">sep =</span> <span class="st">"."</span>),</span>
<span id="cb66-1130"><a href="#cb66-1130" aria-hidden="true" tabindex="-1"></a>      <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"Men.White"</span>, <span class="st">"Men.Black"</span>, <span class="st">"Women.White"</span>, <span class="st">"Women.Black"</span>)</span>
<span id="cb66-1131"><a href="#cb66-1131" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb66-1132"><a href="#cb66-1132" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb66-1133"><a href="#cb66-1133" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1134"><a href="#cb66-1134" aria-hidden="true" tabindex="-1"></a>max_media_receita_a <span class="ot">&lt;-</span> <span class="fu">max</span>(g3_data<span class="sc">$</span>media_receitas_genero_cor)</span>
<span id="cb66-1135"><a href="#cb66-1135" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1136"><a href="#cb66-1136" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1137"><a href="#cb66-1137" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1138"><a href="#cb66-1138" aria-hidden="true" tabindex="-1"></a>Plot figure (Federal Deputy)</span>
<span id="cb66-1139"><a href="#cb66-1139" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1142"><a href="#cb66-1142" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1143"><a href="#cb66-1143" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1144"><a href="#cb66-1144" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1145"><a href="#cb66-1145" aria-hidden="true" tabindex="-1"></a><span class="co">#| class: output</span></span>
<span id="cb66-1146"><a href="#cb66-1146" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: fig-3</span></span>
<span id="cb66-1147"><a href="#cb66-1147" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-cap: "Ratio between the group average and the overall average of public funding of candidates for federal deputy by gender and color/race, each week"</span></span>
<span id="cb66-1148"><a href="#cb66-1148" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-alt: "Ratio between the group average and the overall average of public funding of candidates for federal deputy by gender and color/race, each week"</span></span>
<span id="cb66-1149"><a href="#cb66-1149" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-width: 10</span></span>
<span id="cb66-1150"><a href="#cb66-1150" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-height: 8</span></span>
<span id="cb66-1151"><a href="#cb66-1151" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1152"><a href="#cb66-1152" aria-hidden="true" tabindex="-1"></a><span class="co"># Definir idioma para visualizar data em inglês </span></span>
<span id="cb66-1153"><a href="#cb66-1153" aria-hidden="true" tabindex="-1"></a><span class="fu">invisible</span>(<span class="fu">Sys.setlocale</span>(<span class="st">"LC_TIME"</span>, <span class="st">"English"</span>))</span>
<span id="cb66-1154"><a href="#cb66-1154" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1155"><a href="#cb66-1155" aria-hidden="true" tabindex="-1"></a>limites <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">0</span>, max_media_receita_a) <span class="sc">*</span> <span class="fl">1.1</span></span>
<span id="cb66-1156"><a href="#cb66-1156" aria-hidden="true" tabindex="-1"></a>quebras <span class="ot">&lt;-</span> <span class="fu">seq</span>(limites[<span class="dv">1</span>], limites[<span class="dv">2</span>], <span class="at">by =</span> <span class="dv">20000</span>)</span>
<span id="cb66-1157"><a href="#cb66-1157" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1158"><a href="#cb66-1158" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1159"><a href="#cb66-1159" aria-hidden="true" tabindex="-1"></a><span class="co"># 2018</span></span>
<span id="cb66-1160"><a href="#cb66-1160" aria-hidden="true" tabindex="-1"></a>g3_2018_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb66-1161"><a href="#cb66-1161" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g3_data <span class="sc">%&gt;%</span> </span>
<span id="cb66-1162"><a href="#cb66-1162" aria-hidden="true" tabindex="-1"></a>    <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2018</span>),</span>
<span id="cb66-1163"><a href="#cb66-1163" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(</span>
<span id="cb66-1164"><a href="#cb66-1164" aria-hidden="true" tabindex="-1"></a><span class="co">#    fill = interaction(genero, cor_raca, lex.order = TRUE),</span></span>
<span id="cb66-1165"><a href="#cb66-1165" aria-hidden="true" tabindex="-1"></a>     <span class="at">fill =</span> genero_cor,</span>
<span id="cb66-1166"><a href="#cb66-1166" aria-hidden="true" tabindex="-1"></a>     <span class="at">x =</span> semana_receita, </span>
<span id="cb66-1167"><a href="#cb66-1167" aria-hidden="true" tabindex="-1"></a>      <span class="at">y =</span> media_receitas_genero_cor)) <span class="sc">+</span></span>
<span id="cb66-1168"><a href="#cb66-1168" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb66-1169"><a href="#cb66-1169" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb66-1170"><a href="#cb66-1170" aria-hidden="true" tabindex="-1"></a>    <span class="fu">aes</span>(<span class="at">label =</span> <span class="fu">paste0</span>(</span>
<span id="cb66-1171"><a href="#cb66-1171" aria-hidden="true" tabindex="-1"></a>      <span class="st">"("</span>,</span>
<span id="cb66-1172"><a href="#cb66-1172" aria-hidden="true" tabindex="-1"></a>      <span class="fu">sprintf</span>(<span class="st">"%0.1f"</span>, <span class="fu">round</span>(media_receitas_genero_cor <span class="sc">/</span> media_receitas_semana, <span class="dv">1</span>)),</span>
<span id="cb66-1173"><a href="#cb66-1173" aria-hidden="true" tabindex="-1"></a>      <span class="st">")"</span></span>
<span id="cb66-1174"><a href="#cb66-1174" aria-hidden="true" tabindex="-1"></a>  <span class="co">#   , sep = "")</span></span>
<span id="cb66-1175"><a href="#cb66-1175" aria-hidden="true" tabindex="-1"></a>    )),</span>
<span id="cb66-1176"><a href="#cb66-1176" aria-hidden="true" tabindex="-1"></a>    <span class="at">stat =</span> <span class="st">"identity"</span>,</span>
<span id="cb66-1177"><a href="#cb66-1177" aria-hidden="true" tabindex="-1"></a>    <span class="at">size =</span> <span class="dv">3</span>,</span>
<span id="cb66-1178"><a href="#cb66-1178" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">position_dodge</span>(<span class="dv">6</span>),</span>
<span id="cb66-1179"><a href="#cb66-1179" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust =</span> <span class="sc">-</span><span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb66-1180"><a href="#cb66-1180" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_x_date</span>(</span>
<span id="cb66-1181"><a href="#cb66-1181" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> <span class="fu">as.Date</span>(min_data_campanha_2018),</span>
<span id="cb66-1182"><a href="#cb66-1182" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">date_format</span>(<span class="st">"%b-%d"</span>), </span>
<span id="cb66-1183"><a href="#cb66-1183" aria-hidden="true" tabindex="-1"></a>    <span class="at">breaks =</span> <span class="st">"1 week"</span>) <span class="sc">+</span></span>
<span id="cb66-1184"><a href="#cb66-1184" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb66-1185"><a href="#cb66-1185" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_number</span>(<span class="at">scale_cut =</span> scales<span class="sc">::</span><span class="fu">cut_short_scale</span>()),</span>
<span id="cb66-1186"><a href="#cb66-1186" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> limites, <span class="at">breaks =</span> quebras) <span class="sc">+</span></span>
<span id="cb66-1187"><a href="#cb66-1187" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb66-1188"><a href="#cb66-1188" aria-hidden="true" tabindex="-1"></a>    <span class="at">title =</span> <span class="st">"2018"</span>,</span>
<span id="cb66-1189"><a href="#cb66-1189" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Month - First day of the week"</span>,</span>
<span id="cb66-1190"><a href="#cb66-1190" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Average funding by group (BRL)"</span>,</span>
<span id="cb66-1191"><a href="#cb66-1191" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> <span class="st">"Gender.Race"</span>) <span class="sc">+</span></span>
<span id="cb66-1192"><a href="#cb66-1192" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(<span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"transparent"</span>),</span>
<span id="cb66-1193"><a href="#cb66-1193" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb66-1194"><a href="#cb66-1194" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.y =</span> <span class="fu">element_line</span>(<span class="at">linewidth =</span> <span class="fl">0.1</span>, </span>
<span id="cb66-1195"><a href="#cb66-1195" aria-hidden="true" tabindex="-1"></a>                                          <span class="at">colour =</span> <span class="st">"grey50"</span>),</span>
<span id="cb66-1196"><a href="#cb66-1196" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-1197"><a href="#cb66-1197" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb66-1198"><a href="#cb66-1198" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb66-1199"><a href="#cb66-1199" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>),</span>
<span id="cb66-1200"><a href="#cb66-1200" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>),</span>
<span id="cb66-1201"><a href="#cb66-1201" aria-hidden="true" tabindex="-1"></a>        <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>, <span class="at">face =</span> <span class="st">"bold"</span>),</span>
<span id="cb66-1202"><a href="#cb66-1202" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-1203"><a href="#cb66-1203" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.position =</span> <span class="st">"bottom"</span>)</span>
<span id="cb66-1204"><a href="#cb66-1204" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1205"><a href="#cb66-1205" aria-hidden="true" tabindex="-1"></a><span class="co"># 2022</span></span>
<span id="cb66-1206"><a href="#cb66-1206" aria-hidden="true" tabindex="-1"></a>g3_2022_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb66-1207"><a href="#cb66-1207" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g3_data <span class="sc">%&gt;%</span> </span>
<span id="cb66-1208"><a href="#cb66-1208" aria-hidden="true" tabindex="-1"></a>    <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2022</span>),</span>
<span id="cb66-1209"><a href="#cb66-1209" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(</span>
<span id="cb66-1210"><a href="#cb66-1210" aria-hidden="true" tabindex="-1"></a>  <span class="co">#  fill = interaction(genero, cor_raca, lex.order = TRUE),</span></span>
<span id="cb66-1211"><a href="#cb66-1211" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> genero_cor, </span>
<span id="cb66-1212"><a href="#cb66-1212" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> semana_receita, </span>
<span id="cb66-1213"><a href="#cb66-1213" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> media_receitas_genero_cor)) <span class="sc">+</span></span>
<span id="cb66-1214"><a href="#cb66-1214" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb66-1215"><a href="#cb66-1215" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb66-1216"><a href="#cb66-1216" aria-hidden="true" tabindex="-1"></a>    <span class="fu">aes</span>(<span class="at">label =</span> <span class="fu">paste</span>(</span>
<span id="cb66-1217"><a href="#cb66-1217" aria-hidden="true" tabindex="-1"></a>      <span class="st">"("</span>,</span>
<span id="cb66-1218"><a href="#cb66-1218" aria-hidden="true" tabindex="-1"></a>      <span class="fu">sprintf</span>(<span class="st">"%0.1f"</span>, </span>
<span id="cb66-1219"><a href="#cb66-1219" aria-hidden="true" tabindex="-1"></a>              <span class="fu">round</span>(media_receitas_genero_cor <span class="sc">/</span> media_receitas_semana, <span class="dv">1</span>)), <span class="st">")"</span>,</span>
<span id="cb66-1220"><a href="#cb66-1220" aria-hidden="true" tabindex="-1"></a>      <span class="at">sep =</span> <span class="st">""</span>)),</span>
<span id="cb66-1221"><a href="#cb66-1221" aria-hidden="true" tabindex="-1"></a>    <span class="at">stat =</span> <span class="st">"identity"</span>,</span>
<span id="cb66-1222"><a href="#cb66-1222" aria-hidden="true" tabindex="-1"></a>    <span class="at">size =</span> <span class="dv">3</span>,</span>
<span id="cb66-1223"><a href="#cb66-1223" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">position_dodge</span>(<span class="dv">6</span>),</span>
<span id="cb66-1224"><a href="#cb66-1224" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust =</span> <span class="sc">-</span><span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb66-1225"><a href="#cb66-1225" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_x_date</span>(</span>
<span id="cb66-1226"><a href="#cb66-1226" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> <span class="fu">as.Date</span>(min_data_campanha_2022),</span>
<span id="cb66-1227"><a href="#cb66-1227" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">date_format</span>(<span class="st">"%b-%d"</span>), </span>
<span id="cb66-1228"><a href="#cb66-1228" aria-hidden="true" tabindex="-1"></a>    <span class="at">breaks =</span> <span class="st">"1 week"</span>) <span class="sc">+</span></span>
<span id="cb66-1229"><a href="#cb66-1229" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb66-1230"><a href="#cb66-1230" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_number</span>(<span class="at">scale_cut =</span> scales<span class="sc">::</span><span class="fu">cut_short_scale</span>()),</span>
<span id="cb66-1231"><a href="#cb66-1231" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> limites, <span class="at">breaks =</span> quebras) <span class="sc">+</span></span>
<span id="cb66-1232"><a href="#cb66-1232" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb66-1233"><a href="#cb66-1233" aria-hidden="true" tabindex="-1"></a>    <span class="at">title =</span> <span class="st">"2022"</span>,</span>
<span id="cb66-1234"><a href="#cb66-1234" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Month - First day of the week"</span>,</span>
<span id="cb66-1235"><a href="#cb66-1235" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Average funding by group (BRL)"</span>,</span>
<span id="cb66-1236"><a href="#cb66-1236" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> <span class="st">"Gender.Race"</span>) <span class="sc">+</span></span>
<span id="cb66-1237"><a href="#cb66-1237" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(<span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"transparent"</span>),</span>
<span id="cb66-1238"><a href="#cb66-1238" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb66-1239"><a href="#cb66-1239" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.y =</span> <span class="fu">element_line</span>(<span class="at">linewidth =</span> <span class="fl">0.1</span>, </span>
<span id="cb66-1240"><a href="#cb66-1240" aria-hidden="true" tabindex="-1"></a>                                          <span class="at">colour =</span> <span class="st">"grey50"</span>),</span>
<span id="cb66-1241"><a href="#cb66-1241" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-1242"><a href="#cb66-1242" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb66-1243"><a href="#cb66-1243" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb66-1244"><a href="#cb66-1244" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>),</span>
<span id="cb66-1245"><a href="#cb66-1245" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>),</span>
<span id="cb66-1246"><a href="#cb66-1246" aria-hidden="true" tabindex="-1"></a>        <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>, <span class="at">face =</span> <span class="st">"bold"</span>),</span>
<span id="cb66-1247"><a href="#cb66-1247" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-1248"><a href="#cb66-1248" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.position =</span> <span class="st">"bottom"</span>) <span class="sc">+</span></span>
<span id="cb66-1249"><a href="#cb66-1249" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_vline</span>(</span>
<span id="cb66-1250"><a href="#cb66-1250" aria-hidden="true" tabindex="-1"></a>    <span class="at">xintercept =</span> <span class="fu">as.Date</span>(<span class="st">"2022-09-13"</span>),</span>
<span id="cb66-1251"><a href="#cb66-1251" aria-hidden="true" tabindex="-1"></a>    <span class="at">lwd =</span> <span class="dv">1</span>,</span>
<span id="cb66-1252"><a href="#cb66-1252" aria-hidden="true" tabindex="-1"></a>    <span class="at">linetype =</span> <span class="dv">3</span>,</span>
<span id="cb66-1253"><a href="#cb66-1253" aria-hidden="true" tabindex="-1"></a>    <span class="at">colour=</span><span class="st">"black"</span>) <span class="sc">+</span></span>
<span id="cb66-1254"><a href="#cb66-1254" aria-hidden="true" tabindex="-1"></a>  <span class="fu">annotate</span>(<span class="st">"text"</span>, <span class="at">x=</span><span class="fu">as.Date</span>(<span class="st">"2022-09-12"</span>), <span class="at">y=</span><span class="dv">700000000</span>, </span>
<span id="cb66-1255"><a href="#cb66-1255" aria-hidden="true" tabindex="-1"></a>           <span class="at">label=</span><span class="st">"1st. partial"</span>, <span class="at">angle=</span><span class="dv">90</span>) </span>
<span id="cb66-1256"><a href="#cb66-1256" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1257"><a href="#cb66-1257" aria-hidden="true" tabindex="-1"></a>g3_figure <span class="ot">&lt;-</span> g3_2018_figure <span class="sc">+</span> g3_2022_figure <span class="sc">+</span> <span class="fu">plot_layout</span>(<span class="at">ncol =</span> <span class="dv">1</span>, </span>
<span id="cb66-1258"><a href="#cb66-1258" aria-hidden="true" tabindex="-1"></a>                                                           <span class="at">nrow =</span> <span class="dv">2</span>)</span>
<span id="cb66-1259"><a href="#cb66-1259" aria-hidden="true" tabindex="-1"></a>g3_figure</span>
<span id="cb66-1260"><a href="#cb66-1260" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1261"><a href="#cb66-1261" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1262"><a href="#cb66-1262" aria-hidden="true" tabindex="-1"></a>Save figure (Federal Deputy)</span>
<span id="cb66-1263"><a href="#cb66-1263" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1266"><a href="#cb66-1266" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1267"><a href="#cb66-1267" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1268"><a href="#cb66-1268" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1269"><a href="#cb66-1269" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-fig-3</span></span>
<span id="cb66-1270"><a href="#cb66-1270" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1271"><a href="#cb66-1271" aria-hidden="true" tabindex="-1"></a><span class="fu">grava_figura</span>(<span class="st">"..//Figuras//paper-fig-3"</span>, <span class="st">"png"</span>)</span>
<span id="cb66-1272"><a href="#cb66-1272" aria-hidden="true" tabindex="-1"></a>g3_figure</span>
<span id="cb66-1273"><a href="#cb66-1273" aria-hidden="true" tabindex="-1"></a><span class="fu">dev.off</span>()</span>
<span id="cb66-1274"><a href="#cb66-1274" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1275"><a href="#cb66-1275" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1276"><a href="#cb66-1276" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1277"><a href="#cb66-1277" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1278"><a href="#cb66-1278" aria-hidden="true" tabindex="-1"></a><span class="fu">### Graph 4 - Ratio between the group and the overall average of public funding of candidates for state deputy by gender and color/race, each week</span></span>
<span id="cb66-1279"><a href="#cb66-1279" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1280"><a href="#cb66-1280" aria-hidden="true" tabindex="-1"></a>::: callout-note</span>
<span id="cb66-1281"><a href="#cb66-1281" aria-hidden="true" tabindex="-1"></a>The amount of public revenue for the week received by the group (gender, race) weighted by the number of applications is equivalent to the average public revenue for that week.</span>
<span id="cb66-1282"><a href="#cb66-1282" aria-hidden="true" tabindex="-1"></a>:::</span>
<span id="cb66-1283"><a href="#cb66-1283" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1284"><a href="#cb66-1284" aria-hidden="true" tabindex="-1"></a>Create data object</span>
<span id="cb66-1285"><a href="#cb66-1285" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1288"><a href="#cb66-1288" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1289"><a href="#cb66-1289" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1290"><a href="#cb66-1290" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1291"><a href="#cb66-1291" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: create-g4-data</span></span>
<span id="cb66-1292"><a href="#cb66-1292" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1293"><a href="#cb66-1293" aria-hidden="true" tabindex="-1"></a><span class="co"># State Deputy</span></span>
<span id="cb66-1294"><a href="#cb66-1294" aria-hidden="true" tabindex="-1"></a>g4_data <span class="ot">&lt;-</span>  receitas_publicas_semana_dep_est <span class="sc">%&gt;%</span> </span>
<span id="cb66-1295"><a href="#cb66-1295" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter_at</span>(<span class="fu">vars</span>(<span class="fu">everything</span>()), <span class="fu">all_vars</span>(<span class="sc">!</span><span class="fu">is.na</span>(.))) <span class="sc">%&gt;%</span></span>
<span id="cb66-1296"><a href="#cb66-1296" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb66-1297"><a href="#cb66-1297" aria-hidden="true" tabindex="-1"></a>    genero <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"Men"</span>, <span class="st">"Women"</span>),</span>
<span id="cb66-1298"><a href="#cb66-1298" aria-hidden="true" tabindex="-1"></a>    cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'White'</span>, <span class="st">'Black'</span>))</span>
<span id="cb66-1299"><a href="#cb66-1299" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1300"><a href="#cb66-1300" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1301"><a href="#cb66-1301" aria-hidden="true" tabindex="-1"></a><span class="co"># para alterar a ordem das barras, para ficar como na versão em português</span></span>
<span id="cb66-1302"><a href="#cb66-1302" aria-hidden="true" tabindex="-1"></a>g4_data <span class="ot">&lt;-</span> g4_data <span class="sc">%&gt;%</span></span>
<span id="cb66-1303"><a href="#cb66-1303" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-1304"><a href="#cb66-1304" aria-hidden="true" tabindex="-1"></a>    <span class="at">genero_cor =</span> <span class="fu">factor</span>(</span>
<span id="cb66-1305"><a href="#cb66-1305" aria-hidden="true" tabindex="-1"></a>      <span class="fu">paste</span>(genero, cor_raca, <span class="at">sep =</span> <span class="st">"."</span>),</span>
<span id="cb66-1306"><a href="#cb66-1306" aria-hidden="true" tabindex="-1"></a>      <span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"Men.White"</span>, <span class="st">"Men.Black"</span>, <span class="st">"Women.White"</span>, <span class="st">"Women.Black"</span>)</span>
<span id="cb66-1307"><a href="#cb66-1307" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb66-1308"><a href="#cb66-1308" aria-hidden="true" tabindex="-1"></a>  )</span>
<span id="cb66-1309"><a href="#cb66-1309" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1310"><a href="#cb66-1310" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1311"><a href="#cb66-1311" aria-hidden="true" tabindex="-1"></a>max_media_receita_b <span class="ot">&lt;-</span> <span class="fu">max</span>(g4_data<span class="sc">$</span>media_receitas_genero_cor)</span>
<span id="cb66-1312"><a href="#cb66-1312" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1313"><a href="#cb66-1313" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1314"><a href="#cb66-1314" aria-hidden="true" tabindex="-1"></a>Plot figure (State Deputy)</span>
<span id="cb66-1315"><a href="#cb66-1315" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1318"><a href="#cb66-1318" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1319"><a href="#cb66-1319" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1320"><a href="#cb66-1320" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1321"><a href="#cb66-1321" aria-hidden="true" tabindex="-1"></a><span class="co">#| class: output</span></span>
<span id="cb66-1322"><a href="#cb66-1322" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: fig-4</span></span>
<span id="cb66-1323"><a href="#cb66-1323" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-cap: "Ratio between the group average and the overall average of public funding of candidates for state deputy by gender and race, each week"</span></span>
<span id="cb66-1324"><a href="#cb66-1324" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-alt: "Ratio between the group average and the overall average of public funding of candidates for state deputy by gender and race, each week"</span></span>
<span id="cb66-1325"><a href="#cb66-1325" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-width: 10</span></span>
<span id="cb66-1326"><a href="#cb66-1326" aria-hidden="true" tabindex="-1"></a><span class="co">#| fig-height: 8</span></span>
<span id="cb66-1327"><a href="#cb66-1327" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1328"><a href="#cb66-1328" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1329"><a href="#cb66-1329" aria-hidden="true" tabindex="-1"></a><span class="co"># Definir idioma para visualizar data em inglês </span></span>
<span id="cb66-1330"><a href="#cb66-1330" aria-hidden="true" tabindex="-1"></a><span class="fu">invisible</span>(<span class="fu">Sys.setlocale</span>(<span class="st">"LC_TIME"</span>, <span class="st">"English"</span>))</span>
<span id="cb66-1331"><a href="#cb66-1331" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1332"><a href="#cb66-1332" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1333"><a href="#cb66-1333" aria-hidden="true" tabindex="-1"></a>limites <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">0</span>, max_media_receita_b) <span class="sc">*</span> <span class="fl">1.1</span></span>
<span id="cb66-1334"><a href="#cb66-1334" aria-hidden="true" tabindex="-1"></a>quebras <span class="ot">&lt;-</span> <span class="fu">seq</span>(limites[<span class="dv">1</span>], limites[<span class="dv">2</span>], <span class="at">by =</span> <span class="dv">20000</span>)</span>
<span id="cb66-1335"><a href="#cb66-1335" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1336"><a href="#cb66-1336" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1337"><a href="#cb66-1337" aria-hidden="true" tabindex="-1"></a><span class="co"># 2018</span></span>
<span id="cb66-1338"><a href="#cb66-1338" aria-hidden="true" tabindex="-1"></a>g4_2018_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb66-1339"><a href="#cb66-1339" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g4_data <span class="sc">%&gt;%</span> <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2018</span>),</span>
<span id="cb66-1340"><a href="#cb66-1340" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(</span>
<span id="cb66-1341"><a href="#cb66-1341" aria-hidden="true" tabindex="-1"></a>    <span class="co">#fill = interaction(genero, cor_raca, lex.order = TRUE),</span></span>
<span id="cb66-1342"><a href="#cb66-1342" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill=</span> genero_cor,</span>
<span id="cb66-1343"><a href="#cb66-1343" aria-hidden="true" tabindex="-1"></a>      <span class="at">x =</span> semana_receita, </span>
<span id="cb66-1344"><a href="#cb66-1344" aria-hidden="true" tabindex="-1"></a>      <span class="at">y =</span> media_receitas_genero_cor)) <span class="sc">+</span></span>
<span id="cb66-1345"><a href="#cb66-1345" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb66-1346"><a href="#cb66-1346" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb66-1347"><a href="#cb66-1347" aria-hidden="true" tabindex="-1"></a>    <span class="fu">aes</span>(<span class="at">label =</span> <span class="fu">paste0</span>(</span>
<span id="cb66-1348"><a href="#cb66-1348" aria-hidden="true" tabindex="-1"></a>      <span class="st">"("</span>,</span>
<span id="cb66-1349"><a href="#cb66-1349" aria-hidden="true" tabindex="-1"></a>      <span class="fu">sprintf</span>(<span class="st">"%0.1f"</span>, </span>
<span id="cb66-1350"><a href="#cb66-1350" aria-hidden="true" tabindex="-1"></a>              <span class="fu">round</span>(media_receitas_genero_cor <span class="sc">/</span> media_receitas_semana, <span class="dv">1</span>)),</span>
<span id="cb66-1351"><a href="#cb66-1351" aria-hidden="true" tabindex="-1"></a>      <span class="st">")"</span></span>
<span id="cb66-1352"><a href="#cb66-1352" aria-hidden="true" tabindex="-1"></a>    <span class="co"># , sep = "")),</span></span>
<span id="cb66-1353"><a href="#cb66-1353" aria-hidden="true" tabindex="-1"></a>    )),</span>
<span id="cb66-1354"><a href="#cb66-1354" aria-hidden="true" tabindex="-1"></a>    <span class="at">stat =</span> <span class="st">"identity"</span>,</span>
<span id="cb66-1355"><a href="#cb66-1355" aria-hidden="true" tabindex="-1"></a>    <span class="at">size =</span> <span class="dv">3</span>,</span>
<span id="cb66-1356"><a href="#cb66-1356" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">position_dodge</span>(<span class="dv">6</span>),</span>
<span id="cb66-1357"><a href="#cb66-1357" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust =</span> <span class="sc">-</span><span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb66-1358"><a href="#cb66-1358" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_x_date</span>(</span>
<span id="cb66-1359"><a href="#cb66-1359" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> <span class="fu">as.Date</span>(min_data_campanha_2018),</span>
<span id="cb66-1360"><a href="#cb66-1360" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">date_format</span>(<span class="st">"%b-%d"</span>), </span>
<span id="cb66-1361"><a href="#cb66-1361" aria-hidden="true" tabindex="-1"></a>    <span class="at">breaks =</span> <span class="st">"1 week"</span>) <span class="sc">+</span></span>
<span id="cb66-1362"><a href="#cb66-1362" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb66-1363"><a href="#cb66-1363" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_number</span>(<span class="at">scale_cut =</span> scales<span class="sc">::</span><span class="fu">cut_short_scale</span>()),</span>
<span id="cb66-1364"><a href="#cb66-1364" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> limites, <span class="at">breaks =</span> quebras) <span class="sc">+</span></span>
<span id="cb66-1365"><a href="#cb66-1365" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb66-1366"><a href="#cb66-1366" aria-hidden="true" tabindex="-1"></a>    <span class="at">title =</span> <span class="st">"2018"</span>,</span>
<span id="cb66-1367"><a href="#cb66-1367" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Month - First day of the week"</span>,</span>
<span id="cb66-1368"><a href="#cb66-1368" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Average funding by group (BRL)"</span>,</span>
<span id="cb66-1369"><a href="#cb66-1369" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> <span class="st">"Gender.Race"</span>) <span class="sc">+</span></span>
<span id="cb66-1370"><a href="#cb66-1370" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(<span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"transparent"</span>),</span>
<span id="cb66-1371"><a href="#cb66-1371" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb66-1372"><a href="#cb66-1372" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.y =</span> <span class="fu">element_line</span>(<span class="at">linewidth =</span> <span class="fl">0.1</span>, </span>
<span id="cb66-1373"><a href="#cb66-1373" aria-hidden="true" tabindex="-1"></a>                                          <span class="at">colour =</span> <span class="st">"grey50"</span>),</span>
<span id="cb66-1374"><a href="#cb66-1374" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-1375"><a href="#cb66-1375" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb66-1376"><a href="#cb66-1376" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb66-1377"><a href="#cb66-1377" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>),</span>
<span id="cb66-1378"><a href="#cb66-1378" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>),</span>
<span id="cb66-1379"><a href="#cb66-1379" aria-hidden="true" tabindex="-1"></a>        <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>, <span class="at">face =</span> <span class="st">"bold"</span>),</span>
<span id="cb66-1380"><a href="#cb66-1380" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-1381"><a href="#cb66-1381" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.position =</span> <span class="st">"bottom"</span>)</span>
<span id="cb66-1382"><a href="#cb66-1382" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1383"><a href="#cb66-1383" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1384"><a href="#cb66-1384" aria-hidden="true" tabindex="-1"></a><span class="co"># 2022</span></span>
<span id="cb66-1385"><a href="#cb66-1385" aria-hidden="true" tabindex="-1"></a>g4_2022_figure <span class="ot">&lt;-</span> <span class="fu">ggplot</span>(</span>
<span id="cb66-1386"><a href="#cb66-1386" aria-hidden="true" tabindex="-1"></a>  <span class="at">data =</span> g4_data <span class="sc">%&gt;%</span> <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2022</span>),</span>
<span id="cb66-1387"><a href="#cb66-1387" aria-hidden="true" tabindex="-1"></a>  <span class="fu">aes</span>(</span>
<span id="cb66-1388"><a href="#cb66-1388" aria-hidden="true" tabindex="-1"></a>  <span class="co">#  fill = interaction(genero, cor_raca, lex.order = TRUE),</span></span>
<span id="cb66-1389"><a href="#cb66-1389" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> genero_cor,</span>
<span id="cb66-1390"><a href="#cb66-1390" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> semana_receita, </span>
<span id="cb66-1391"><a href="#cb66-1391" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> media_receitas_genero_cor)) <span class="sc">+</span></span>
<span id="cb66-1392"><a href="#cb66-1392" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_bar</span>(<span class="at">position =</span> <span class="st">"dodge"</span>, <span class="at">stat =</span> <span class="st">"identity"</span>) <span class="sc">+</span></span>
<span id="cb66-1393"><a href="#cb66-1393" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_text</span>(</span>
<span id="cb66-1394"><a href="#cb66-1394" aria-hidden="true" tabindex="-1"></a>    <span class="fu">aes</span>(<span class="at">label =</span> <span class="fu">paste</span>(</span>
<span id="cb66-1395"><a href="#cb66-1395" aria-hidden="true" tabindex="-1"></a>      <span class="st">"("</span>,</span>
<span id="cb66-1396"><a href="#cb66-1396" aria-hidden="true" tabindex="-1"></a>      <span class="fu">sprintf</span>(<span class="st">"%0.1f"</span>, </span>
<span id="cb66-1397"><a href="#cb66-1397" aria-hidden="true" tabindex="-1"></a>              <span class="fu">round</span>(media_receitas_genero_cor <span class="sc">/</span> media_receitas_semana, <span class="dv">1</span>)),</span>
<span id="cb66-1398"><a href="#cb66-1398" aria-hidden="true" tabindex="-1"></a>      <span class="st">")"</span>,</span>
<span id="cb66-1399"><a href="#cb66-1399" aria-hidden="true" tabindex="-1"></a>      <span class="at">sep =</span> <span class="st">""</span>)),</span>
<span id="cb66-1400"><a href="#cb66-1400" aria-hidden="true" tabindex="-1"></a>    <span class="at">stat =</span> <span class="st">"identity"</span>,</span>
<span id="cb66-1401"><a href="#cb66-1401" aria-hidden="true" tabindex="-1"></a>    <span class="at">size =</span> <span class="dv">3</span>,</span>
<span id="cb66-1402"><a href="#cb66-1402" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">position_dodge</span>(<span class="dv">6</span>),</span>
<span id="cb66-1403"><a href="#cb66-1403" aria-hidden="true" tabindex="-1"></a>    <span class="at">vjust =</span> <span class="sc">-</span><span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb66-1404"><a href="#cb66-1404" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_x_date</span>(</span>
<span id="cb66-1405"><a href="#cb66-1405" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> <span class="fu">as.Date</span>(min_data_campanha_2022),</span>
<span id="cb66-1406"><a href="#cb66-1406" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">date_format</span>(<span class="st">"%b-%d"</span>), </span>
<span id="cb66-1407"><a href="#cb66-1407" aria-hidden="true" tabindex="-1"></a>    <span class="at">breaks =</span> <span class="st">"1 week"</span>) <span class="sc">+</span></span>
<span id="cb66-1408"><a href="#cb66-1408" aria-hidden="true" tabindex="-1"></a>  <span class="fu">scale_y_continuous</span>(</span>
<span id="cb66-1409"><a href="#cb66-1409" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> scales<span class="sc">::</span><span class="fu">label_number</span>(<span class="at">scale_cut =</span> scales<span class="sc">::</span><span class="fu">cut_short_scale</span>()),</span>
<span id="cb66-1410"><a href="#cb66-1410" aria-hidden="true" tabindex="-1"></a>    <span class="at">limits =</span> limites, <span class="at">breaks =</span> quebras) <span class="sc">+</span></span>
<span id="cb66-1411"><a href="#cb66-1411" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labs</span>(</span>
<span id="cb66-1412"><a href="#cb66-1412" aria-hidden="true" tabindex="-1"></a>    <span class="at">title =</span> <span class="st">"2022"</span>,</span>
<span id="cb66-1413"><a href="#cb66-1413" aria-hidden="true" tabindex="-1"></a>    <span class="at">x =</span> <span class="st">"Month - First day of the week"</span>,</span>
<span id="cb66-1414"><a href="#cb66-1414" aria-hidden="true" tabindex="-1"></a>    <span class="at">y =</span> <span class="st">"Average funding by group (BRL)"</span>,</span>
<span id="cb66-1415"><a href="#cb66-1415" aria-hidden="true" tabindex="-1"></a>    <span class="at">fill =</span> <span class="st">"Gender.Race"</span>) <span class="sc">+</span></span>
<span id="cb66-1416"><a href="#cb66-1416" aria-hidden="true" tabindex="-1"></a>  <span class="fu">theme</span>(<span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"transparent"</span>),</span>
<span id="cb66-1417"><a href="#cb66-1417" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.x =</span> <span class="fu">element_blank</span>(), </span>
<span id="cb66-1418"><a href="#cb66-1418" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.major.y =</span> <span class="fu">element_line</span>(<span class="at">linewidth =</span> <span class="fl">0.1</span>, </span>
<span id="cb66-1419"><a href="#cb66-1419" aria-hidden="true" tabindex="-1"></a>                                          <span class="at">colour =</span> <span class="st">"grey50"</span>),</span>
<span id="cb66-1420"><a href="#cb66-1420" aria-hidden="true" tabindex="-1"></a>        <span class="at">panel.grid.minor =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-1421"><a href="#cb66-1421" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb66-1422"><a href="#cb66-1422" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.text.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>),</span>
<span id="cb66-1423"><a href="#cb66-1423" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>),</span>
<span id="cb66-1424"><a href="#cb66-1424" aria-hidden="true" tabindex="-1"></a>        <span class="at">axis.title.y =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">11</span>),</span>
<span id="cb66-1425"><a href="#cb66-1425" aria-hidden="true" tabindex="-1"></a>        <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">12</span>, <span class="at">face =</span> <span class="st">"bold"</span>),</span>
<span id="cb66-1426"><a href="#cb66-1426" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.title =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb66-1427"><a href="#cb66-1427" aria-hidden="true" tabindex="-1"></a>        <span class="at">legend.position =</span> <span class="st">"bottom"</span>) <span class="sc">+</span></span>
<span id="cb66-1428"><a href="#cb66-1428" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_vline</span>(</span>
<span id="cb66-1429"><a href="#cb66-1429" aria-hidden="true" tabindex="-1"></a>    <span class="at">xintercept =</span> <span class="fu">as.Date</span>(<span class="st">"2022-09-13"</span>),</span>
<span id="cb66-1430"><a href="#cb66-1430" aria-hidden="true" tabindex="-1"></a>    <span class="at">lwd =</span> <span class="dv">1</span>,</span>
<span id="cb66-1431"><a href="#cb66-1431" aria-hidden="true" tabindex="-1"></a>    <span class="at">linetype =</span> <span class="dv">3</span>,</span>
<span id="cb66-1432"><a href="#cb66-1432" aria-hidden="true" tabindex="-1"></a>    <span class="at">colour=</span><span class="st">"black"</span>) <span class="sc">+</span></span>
<span id="cb66-1433"><a href="#cb66-1433" aria-hidden="true" tabindex="-1"></a>  <span class="fu">annotate</span>(<span class="st">"text"</span>, <span class="at">x=</span><span class="fu">as.Date</span>(<span class="st">"2022-09-12"</span>), <span class="at">y=</span><span class="dv">700000000</span>, </span>
<span id="cb66-1434"><a href="#cb66-1434" aria-hidden="true" tabindex="-1"></a>           <span class="at">label=</span><span class="st">"1a. parcial"</span>, <span class="at">angle=</span><span class="dv">90</span>) </span>
<span id="cb66-1435"><a href="#cb66-1435" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1436"><a href="#cb66-1436" aria-hidden="true" tabindex="-1"></a>g4_figure <span class="ot">&lt;-</span> g4_2018_figure <span class="sc">+</span> g4_2022_figure <span class="sc">+</span> <span class="fu">plot_layout</span>(<span class="at">ncol =</span> <span class="dv">1</span>, </span>
<span id="cb66-1437"><a href="#cb66-1437" aria-hidden="true" tabindex="-1"></a>                                                           <span class="at">nrow =</span> <span class="dv">2</span>)</span>
<span id="cb66-1438"><a href="#cb66-1438" aria-hidden="true" tabindex="-1"></a>g4_figure</span>
<span id="cb66-1439"><a href="#cb66-1439" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1440"><a href="#cb66-1440" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1441"><a href="#cb66-1441" aria-hidden="true" tabindex="-1"></a>Save figure (State Deputy)</span>
<span id="cb66-1442"><a href="#cb66-1442" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1445"><a href="#cb66-1445" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1446"><a href="#cb66-1446" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1447"><a href="#cb66-1447" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1448"><a href="#cb66-1448" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-fig-4</span></span>
<span id="cb66-1449"><a href="#cb66-1449" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1450"><a href="#cb66-1450" aria-hidden="true" tabindex="-1"></a><span class="co"># save figure in PNG format</span></span>
<span id="cb66-1451"><a href="#cb66-1451" aria-hidden="true" tabindex="-1"></a><span class="fu">grava_figura</span>(<span class="st">"..//Figuras//paper-fig-4"</span>, <span class="st">"png"</span>)</span>
<span id="cb66-1452"><a href="#cb66-1452" aria-hidden="true" tabindex="-1"></a>g4_figure</span>
<span id="cb66-1453"><a href="#cb66-1453" aria-hidden="true" tabindex="-1"></a><span class="fu">dev.off</span>()</span>
<span id="cb66-1454"><a href="#cb66-1454" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1455"><a href="#cb66-1455" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1456"><a href="#cb66-1456" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1457"><a href="#cb66-1457" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1458"><a href="#cb66-1458" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1459"><a href="#cb66-1459" aria-hidden="true" tabindex="-1"></a><span class="fu">## Transfers between candidate providers</span></span>
<span id="cb66-1460"><a href="#cb66-1460" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1461"><a href="#cb66-1461" aria-hidden="true" tabindex="-1"></a>Define the format style of the tables</span>
<span id="cb66-1462"><a href="#cb66-1462" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1465"><a href="#cb66-1465" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1466"><a href="#cb66-1466" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1467"><a href="#cb66-1467" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1468"><a href="#cb66-1468" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: format-table-styles</span></span>
<span id="cb66-1469"><a href="#cb66-1469" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1470"><a href="#cb66-1470" aria-hidden="true" tabindex="-1"></a><span class="fu">set_flextable_defaults</span>(</span>
<span id="cb66-1471"><a href="#cb66-1471" aria-hidden="true" tabindex="-1"></a>  <span class="at">split =</span> <span class="cn">TRUE</span>,</span>
<span id="cb66-1472"><a href="#cb66-1472" aria-hidden="true" tabindex="-1"></a>  <span class="at">table_align =</span> <span class="st">"center"</span>,</span>
<span id="cb66-1473"><a href="#cb66-1473" aria-hidden="true" tabindex="-1"></a>  <span class="at">digits =</span> <span class="dv">2</span>, </span>
<span id="cb66-1474"><a href="#cb66-1474" aria-hidden="true" tabindex="-1"></a>  <span class="at">border.color =</span> <span class="st">"black"</span>)</span>
<span id="cb66-1475"><a href="#cb66-1475" aria-hidden="true" tabindex="-1"></a>properties1 <span class="ot">&lt;-</span> <span class="fu">fp_text</span>(<span class="at">font.family =</span> <span class="st">"Times New Roman"</span>,</span>
<span id="cb66-1476"><a href="#cb66-1476" aria-hidden="true" tabindex="-1"></a>                      <span class="at">font.size =</span> <span class="dv">10</span>)</span>
<span id="cb66-1477"><a href="#cb66-1477" aria-hidden="true" tabindex="-1"></a>properties2 <span class="ot">&lt;-</span> <span class="fu">fp_text</span>(<span class="at">font.family =</span> <span class="st">"Times New Roman"</span>,</span>
<span id="cb66-1478"><a href="#cb66-1478" aria-hidden="true" tabindex="-1"></a>                      <span class="at">font.size =</span> <span class="dv">10</span>,</span>
<span id="cb66-1479"><a href="#cb66-1479" aria-hidden="true" tabindex="-1"></a>                      <span class="at">bold =</span> <span class="cn">TRUE</span>)</span>
<span id="cb66-1480"><a href="#cb66-1480" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1481"><a href="#cb66-1481" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1482"><a href="#cb66-1482" aria-hidden="true" tabindex="-1"></a><span class="fu">### Table 1 - Transfer of funds between candidates, by gender</span></span>
<span id="cb66-1483"><a href="#cb66-1483" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1484"><a href="#cb66-1484" aria-hidden="true" tabindex="-1"></a>::: callout-note</span>
<span id="cb66-1485"><a href="#cb66-1485" aria-hidden="true" tabindex="-1"></a>Here, we consider only funding originating from public revenue.</span>
<span id="cb66-1486"><a href="#cb66-1486" aria-hidden="true" tabindex="-1"></a>:::</span>
<span id="cb66-1487"><a href="#cb66-1487" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1488"><a href="#cb66-1488" aria-hidden="true" tabindex="-1"></a>Create dataset for table 1</span>
<span id="cb66-1489"><a href="#cb66-1489" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1492"><a href="#cb66-1492" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1493"><a href="#cb66-1493" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1494"><a href="#cb66-1494" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1495"><a href="#cb66-1495" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: create-data-table-1</span></span>
<span id="cb66-1496"><a href="#cb66-1496" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1497"><a href="#cb66-1497" aria-hidden="true" tabindex="-1"></a>d_t_1 <span class="ot">&lt;-</span> receitas <span class="sc">%&gt;%</span></span>
<span id="cb66-1498"><a href="#cb66-1498" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2022</span>,</span>
<span id="cb66-1499"><a href="#cb66-1499" aria-hidden="true" tabindex="-1"></a>         NR_CPF_CNPJ_DOADOR <span class="sc">!=</span> NR_CNPJ_PRESTADOR_CONTA,</span>
<span id="cb66-1500"><a href="#cb66-1500" aria-hidden="true" tabindex="-1"></a>         DS_FONTE_RECURSO <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'Recursos de outros candidatos'</span>, </span>
<span id="cb66-1501"><a href="#cb66-1501" aria-hidden="true" tabindex="-1"></a>                                 <span class="st">'Recursos de partido político'</span>),</span>
<span id="cb66-1502"><a href="#cb66-1502" aria-hidden="true" tabindex="-1"></a>         tipo_recurso <span class="sc">==</span> <span class="st">'Public'</span>,</span>
<span id="cb66-1503"><a href="#cb66-1503" aria-hidden="true" tabindex="-1"></a>         genero <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'Men'</span>, <span class="st">'Women'</span>),</span>
<span id="cb66-1504"><a href="#cb66-1504" aria-hidden="true" tabindex="-1"></a>         genero_doador <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'Men'</span>, <span class="st">'Women'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1505"><a href="#cb66-1505" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb66-1506"><a href="#cb66-1506" aria-hidden="true" tabindex="-1"></a>         <span class="at">position =</span> DS_CARGO,</span>
<span id="cb66-1507"><a href="#cb66-1507" aria-hidden="true" tabindex="-1"></a>         <span class="at">gender_accountaunt =</span> genero,</span>
<span id="cb66-1508"><a href="#cb66-1508" aria-hidden="true" tabindex="-1"></a>         <span class="at">gender_donor =</span> genero_doador) <span class="sc">%&gt;%</span></span>
<span id="cb66-1509"><a href="#cb66-1509" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span><span class="fu">c</span>(ano_eleicao, DS_CARGO, genero, genero_doador)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1510"><a href="#cb66-1510" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(gender_donor, gender_accountaunt) <span class="sc">%&gt;%</span></span>
<span id="cb66-1511"><a href="#cb66-1511" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">transfers_between_accountants =</span> <span class="fu">sum</span>(TOTAL_RECEITA),</span>
<span id="cb66-1512"><a href="#cb66-1512" aria-hidden="true" tabindex="-1"></a>            <span class="at">.groups =</span> <span class="st">'drop'</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-1513"><a href="#cb66-1513" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-1514"><a href="#cb66-1514" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(gender_donor) <span class="sc">%&gt;%</span></span>
<span id="cb66-1515"><a href="#cb66-1515" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-1516"><a href="#cb66-1516" aria-hidden="true" tabindex="-1"></a>    <span class="at">prc_transfers_rel_gender_donor =</span> transfers_between_accountants <span class="sc">/</span> </span>
<span id="cb66-1517"><a href="#cb66-1517" aria-hidden="true" tabindex="-1"></a>        <span class="fu">sum</span>(transfers_between_accountants)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1518"><a href="#cb66-1518" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-1519"><a href="#cb66-1519" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-1520"><a href="#cb66-1520" aria-hidden="true" tabindex="-1"></a>      <span class="at">prc_transfers_rel_total =</span> transfers_between_accountants <span class="sc">/</span> </span>
<span id="cb66-1521"><a href="#cb66-1521" aria-hidden="true" tabindex="-1"></a>        <span class="fu">sum</span>(transfers_between_accountants)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1522"><a href="#cb66-1522" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(gender_donor, gender_accountaunt, </span>
<span id="cb66-1523"><a href="#cb66-1523" aria-hidden="true" tabindex="-1"></a>         transfers_between_accountants,</span>
<span id="cb66-1524"><a href="#cb66-1524" aria-hidden="true" tabindex="-1"></a>         prc_transfers_rel_total,</span>
<span id="cb66-1525"><a href="#cb66-1525" aria-hidden="true" tabindex="-1"></a>         prc_transfers_rel_gender_donor) <span class="sc">%&gt;%</span></span>
<span id="cb66-1526"><a href="#cb66-1526" aria-hidden="true" tabindex="-1"></a>  <span class="fu">as_tibble</span>()</span>
<span id="cb66-1527"><a href="#cb66-1527" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1528"><a href="#cb66-1528" aria-hidden="true" tabindex="-1"></a>d_t_1</span>
<span id="cb66-1529"><a href="#cb66-1529" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1530"><a href="#cb66-1530" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1531"><a href="#cb66-1531" aria-hidden="true" tabindex="-1"></a>Plot table 1 (HTML format)</span>
<span id="cb66-1532"><a href="#cb66-1532" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1535"><a href="#cb66-1535" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1536"><a href="#cb66-1536" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1537"><a href="#cb66-1537" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1538"><a href="#cb66-1538" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-1</span></span>
<span id="cb66-1539"><a href="#cb66-1539" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1540"><a href="#cb66-1540" aria-hidden="true" tabindex="-1"></a>t_1 <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(d_t_1) <span class="sc">|&gt;</span></span>
<span id="cb66-1541"><a href="#cb66-1541" aria-hidden="true" tabindex="-1"></a>  <span class="fu">delete_part</span>(<span class="st">"foot"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1542"><a href="#cb66-1542" aria-hidden="true" tabindex="-1"></a>  <span class="fu">delete_rows</span>(<span class="at">i =</span> <span class="dv">2</span>, <span class="at">part =</span> <span class="st">"header"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1543"><a href="#cb66-1543" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mk_par</span>(</span>
<span id="cb66-1544"><a href="#cb66-1544" aria-hidden="true" tabindex="-1"></a>    <span class="at">j =</span> <span class="dv">4</span>, <span class="at">part =</span> <span class="st">"body"</span>,</span>
<span id="cb66-1545"><a href="#cb66-1545" aria-hidden="true" tabindex="-1"></a>    <span class="at">value =</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_transfers_rel_total,</span>
<span id="cb66-1546"><a href="#cb66-1546" aria-hidden="true" tabindex="-1"></a>                                  <span class="at">formatter =</span> fmt_pct))) <span class="sc">|&gt;</span></span>
<span id="cb66-1547"><a href="#cb66-1547" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mk_par</span>(</span>
<span id="cb66-1548"><a href="#cb66-1548" aria-hidden="true" tabindex="-1"></a>    <span class="at">j =</span> <span class="dv">5</span>, <span class="at">part =</span> <span class="st">"body"</span>,</span>
<span id="cb66-1549"><a href="#cb66-1549" aria-hidden="true" tabindex="-1"></a>    <span class="at">value =</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_transfers_rel_gender_donor,</span>
<span id="cb66-1550"><a href="#cb66-1550" aria-hidden="true" tabindex="-1"></a>                                  <span class="at">formatter =</span> fmt_pct))) <span class="sc">|&gt;</span></span>
<span id="cb66-1551"><a href="#cb66-1551" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-1552"><a href="#cb66-1552" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-1553"><a href="#cb66-1553" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-1554"><a href="#cb66-1554" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender_accountaunt"</span> <span class="ot">=</span> <span class="st">"Accountant gender"</span>,</span>
<span id="cb66-1555"><a href="#cb66-1555" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender_donor"</span> <span class="ot">=</span> <span class="st">"Donor gender"</span>,</span>
<span id="cb66-1556"><a href="#cb66-1556" aria-hidden="true" tabindex="-1"></a>      <span class="st">"transfers_between_accountants"</span> <span class="ot">=</span> <span class="st">"Transfer amount (BRL)"</span>,</span>
<span id="cb66-1557"><a href="#cb66-1557" aria-hidden="true" tabindex="-1"></a>      <span class="st">"prc_transfers_rel_total"</span> <span class="ot">=</span> <span class="st">"% (rel. total)"</span>,</span>
<span id="cb66-1558"><a href="#cb66-1558" aria-hidden="true" tabindex="-1"></a>      <span class="st">"prc_transfers_rel_gender_donor"</span> <span class="ot">=</span> <span class="st">"% (rel. donor gender)"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-1559"><a href="#cb66-1559" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1560"><a href="#cb66-1560" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">1.25</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1561"><a href="#cb66-1561" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1562"><a href="#cb66-1562" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1563"><a href="#cb66-1563" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-1564"><a href="#cb66-1564" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1565"><a href="#cb66-1565" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1566"><a href="#cb66-1566" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-1567"><a href="#cb66-1567" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-1568"><a href="#cb66-1568" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1569"><a href="#cb66-1569" aria-hidden="true" tabindex="-1"></a>t_1</span>
<span id="cb66-1570"><a href="#cb66-1570" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1571"><a href="#cb66-1571" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1572"><a href="#cb66-1572" aria-hidden="true" tabindex="-1"></a>Save table 1 (XLSX and DOCX format)</span>
<span id="cb66-1573"><a href="#cb66-1573" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1576"><a href="#cb66-1576" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1577"><a href="#cb66-1577" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1578"><a href="#cb66-1578" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1579"><a href="#cb66-1579" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-table-1</span></span>
<span id="cb66-1580"><a href="#cb66-1580" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1581"><a href="#cb66-1581" aria-hidden="true" tabindex="-1"></a><span class="co"># XLSX</span></span>
<span id="cb66-1582"><a href="#cb66-1582" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(d_t_1, </span>
<span id="cb66-1583"><a href="#cb66-1583" aria-hidden="true" tabindex="-1"></a>           <span class="st">'..//Tabelas//Paper_Table_1_Dataset.xlsx'</span>)</span>
<span id="cb66-1584"><a href="#cb66-1584" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1585"><a href="#cb66-1585" aria-hidden="true" tabindex="-1"></a><span class="co"># DOCX</span></span>
<span id="cb66-1586"><a href="#cb66-1586" aria-hidden="true" tabindex="-1"></a>path <span class="ot">&lt;-</span> <span class="st">'..//Tabelas/Paper_Table_1_R.docx'</span></span>
<span id="cb66-1587"><a href="#cb66-1587" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb66-1588"><a href="#cb66-1588" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value=</span>t_1)</span>
<span id="cb66-1589"><a href="#cb66-1589" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span>
<span id="cb66-1590"><a href="#cb66-1590" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1591"><a href="#cb66-1591" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1592"><a href="#cb66-1592" aria-hidden="true" tabindex="-1"></a><span class="fu">### Table 2 - Transfer of funds between candidates, by race</span></span>
<span id="cb66-1593"><a href="#cb66-1593" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1594"><a href="#cb66-1594" aria-hidden="true" tabindex="-1"></a>::: callout-note</span>
<span id="cb66-1595"><a href="#cb66-1595" aria-hidden="true" tabindex="-1"></a>Here, we consider only funding originating from public revenue. The candidate who donates is called the donor, and the candidate who receives the donation is called the accountant.</span>
<span id="cb66-1596"><a href="#cb66-1596" aria-hidden="true" tabindex="-1"></a>:::</span>
<span id="cb66-1597"><a href="#cb66-1597" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1598"><a href="#cb66-1598" aria-hidden="true" tabindex="-1"></a>Create dataset for table 2</span>
<span id="cb66-1599"><a href="#cb66-1599" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1602"><a href="#cb66-1602" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1603"><a href="#cb66-1603" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1604"><a href="#cb66-1604" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1605"><a href="#cb66-1605" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: create-data-table-2</span></span>
<span id="cb66-1606"><a href="#cb66-1606" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1607"><a href="#cb66-1607" aria-hidden="true" tabindex="-1"></a>d_t_2 <span class="ot">&lt;-</span> receitas <span class="sc">%&gt;%</span></span>
<span id="cb66-1608"><a href="#cb66-1608" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(ano_eleicao <span class="sc">==</span> <span class="dv">2022</span>,</span>
<span id="cb66-1609"><a href="#cb66-1609" aria-hidden="true" tabindex="-1"></a>         NR_CPF_CNPJ_DOADOR <span class="sc">!=</span> NR_CNPJ_PRESTADOR_CONTA,</span>
<span id="cb66-1610"><a href="#cb66-1610" aria-hidden="true" tabindex="-1"></a>         DS_FONTE_RECURSO <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'Recursos de outros candidatos'</span>, </span>
<span id="cb66-1611"><a href="#cb66-1611" aria-hidden="true" tabindex="-1"></a>                                 <span class="st">'Recursos de partido político'</span>),</span>
<span id="cb66-1612"><a href="#cb66-1612" aria-hidden="true" tabindex="-1"></a>         tipo_recurso <span class="sc">==</span> <span class="st">'Public'</span>,</span>
<span id="cb66-1613"><a href="#cb66-1613" aria-hidden="true" tabindex="-1"></a>         cor_raca_doador <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'White'</span>, <span class="st">'Black'</span>),</span>
<span id="cb66-1614"><a href="#cb66-1614" aria-hidden="true" tabindex="-1"></a>         cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'White'</span>, <span class="st">'Black'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1615"><a href="#cb66-1615" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb66-1616"><a href="#cb66-1616" aria-hidden="true" tabindex="-1"></a>         <span class="at">position =</span> DS_CARGO,</span>
<span id="cb66-1617"><a href="#cb66-1617" aria-hidden="true" tabindex="-1"></a>         <span class="at">gender =</span> genero,</span>
<span id="cb66-1618"><a href="#cb66-1618" aria-hidden="true" tabindex="-1"></a>         <span class="at">gender_donor =</span> genero_doador,</span>
<span id="cb66-1619"><a href="#cb66-1619" aria-hidden="true" tabindex="-1"></a>         <span class="at">race_donor =</span> cor_raca_doador,</span>
<span id="cb66-1620"><a href="#cb66-1620" aria-hidden="true" tabindex="-1"></a>         <span class="at">race_accountant =</span> cor_raca) <span class="sc">%&gt;%</span></span>
<span id="cb66-1621"><a href="#cb66-1621" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span><span class="fu">c</span>(ano_eleicao, DS_CARGO, genero, genero_doador,</span>
<span id="cb66-1622"><a href="#cb66-1622" aria-hidden="true" tabindex="-1"></a>            cor_raca, cor_raca_doador)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1623"><a href="#cb66-1623" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(race_donor, race_accountant) <span class="sc">%&gt;%</span></span>
<span id="cb66-1624"><a href="#cb66-1624" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">transfers_between_accountants =</span> <span class="fu">sum</span>(TOTAL_RECEITA),</span>
<span id="cb66-1625"><a href="#cb66-1625" aria-hidden="true" tabindex="-1"></a>            <span class="at">.groups =</span> <span class="st">'drop'</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-1626"><a href="#cb66-1626" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-1627"><a href="#cb66-1627" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(race_donor) <span class="sc">%&gt;%</span></span>
<span id="cb66-1628"><a href="#cb66-1628" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-1629"><a href="#cb66-1629" aria-hidden="true" tabindex="-1"></a>    <span class="at">prc_transfers_rel_race_donor =</span> transfers_between_accountants <span class="sc">/</span> </span>
<span id="cb66-1630"><a href="#cb66-1630" aria-hidden="true" tabindex="-1"></a>        <span class="fu">sum</span>(transfers_between_accountants)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1631"><a href="#cb66-1631" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-1632"><a href="#cb66-1632" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-1633"><a href="#cb66-1633" aria-hidden="true" tabindex="-1"></a>      <span class="at">prc_transfers_rel_total =</span> transfers_between_accountants <span class="sc">/</span> </span>
<span id="cb66-1634"><a href="#cb66-1634" aria-hidden="true" tabindex="-1"></a>        <span class="fu">sum</span>(transfers_between_accountants)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1635"><a href="#cb66-1635" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(race_donor, race_accountant, </span>
<span id="cb66-1636"><a href="#cb66-1636" aria-hidden="true" tabindex="-1"></a>         transfers_between_accountants,</span>
<span id="cb66-1637"><a href="#cb66-1637" aria-hidden="true" tabindex="-1"></a>         prc_transfers_rel_total,</span>
<span id="cb66-1638"><a href="#cb66-1638" aria-hidden="true" tabindex="-1"></a>         prc_transfers_rel_race_donor) <span class="sc">%&gt;%</span></span>
<span id="cb66-1639"><a href="#cb66-1639" aria-hidden="true" tabindex="-1"></a>  <span class="fu">as_tibble</span>()</span>
<span id="cb66-1640"><a href="#cb66-1640" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1641"><a href="#cb66-1641" aria-hidden="true" tabindex="-1"></a>d_t_2</span>
<span id="cb66-1642"><a href="#cb66-1642" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1643"><a href="#cb66-1643" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1644"><a href="#cb66-1644" aria-hidden="true" tabindex="-1"></a>Plot table 2 (HTML format)</span>
<span id="cb66-1645"><a href="#cb66-1645" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1648"><a href="#cb66-1648" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1649"><a href="#cb66-1649" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1650"><a href="#cb66-1650" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1651"><a href="#cb66-1651" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-2</span></span>
<span id="cb66-1652"><a href="#cb66-1652" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1653"><a href="#cb66-1653" aria-hidden="true" tabindex="-1"></a>t_2 <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(d_t_2) <span class="sc">|&gt;</span></span>
<span id="cb66-1654"><a href="#cb66-1654" aria-hidden="true" tabindex="-1"></a>  <span class="fu">delete_part</span>(<span class="st">"foot"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1655"><a href="#cb66-1655" aria-hidden="true" tabindex="-1"></a>  <span class="fu">delete_rows</span>(<span class="at">i =</span> <span class="dv">2</span>, <span class="at">part =</span> <span class="st">"header"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1656"><a href="#cb66-1656" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mk_par</span>(</span>
<span id="cb66-1657"><a href="#cb66-1657" aria-hidden="true" tabindex="-1"></a>    <span class="at">j =</span> <span class="dv">4</span>, <span class="at">part =</span> <span class="st">"body"</span>,</span>
<span id="cb66-1658"><a href="#cb66-1658" aria-hidden="true" tabindex="-1"></a>    <span class="at">value =</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_transfers_rel_total,</span>
<span id="cb66-1659"><a href="#cb66-1659" aria-hidden="true" tabindex="-1"></a>                                  <span class="at">formatter =</span> fmt_pct))) <span class="sc">|&gt;</span></span>
<span id="cb66-1660"><a href="#cb66-1660" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mk_par</span>(</span>
<span id="cb66-1661"><a href="#cb66-1661" aria-hidden="true" tabindex="-1"></a>    <span class="at">j =</span> <span class="dv">5</span>, <span class="at">part =</span> <span class="st">"body"</span>,</span>
<span id="cb66-1662"><a href="#cb66-1662" aria-hidden="true" tabindex="-1"></a>    <span class="at">value =</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_transfers_rel_race_donor,</span>
<span id="cb66-1663"><a href="#cb66-1663" aria-hidden="true" tabindex="-1"></a>                                  <span class="at">formatter =</span> fmt_pct))) <span class="sc">|&gt;</span></span>
<span id="cb66-1664"><a href="#cb66-1664" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-1665"><a href="#cb66-1665" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-1666"><a href="#cb66-1666" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-1667"><a href="#cb66-1667" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_accountant"</span> <span class="ot">=</span> <span class="st">"Accountant race/color"</span>,</span>
<span id="cb66-1668"><a href="#cb66-1668" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_donor"</span> <span class="ot">=</span> <span class="st">"Donor race/color"</span>,</span>
<span id="cb66-1669"><a href="#cb66-1669" aria-hidden="true" tabindex="-1"></a>      <span class="st">"transfers_between_accountants"</span> <span class="ot">=</span> <span class="st">"Transfer amount (BRL)"</span>,</span>
<span id="cb66-1670"><a href="#cb66-1670" aria-hidden="true" tabindex="-1"></a>      <span class="st">"prc_transfers_rel_total"</span> <span class="ot">=</span> <span class="st">"% (rel. total)"</span>,</span>
<span id="cb66-1671"><a href="#cb66-1671" aria-hidden="true" tabindex="-1"></a>      <span class="st">"prc_transfers_rel_race_donor"</span> <span class="ot">=</span> <span class="st">"% (rel. donor race/color)"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-1672"><a href="#cb66-1672" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1673"><a href="#cb66-1673" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">1.25</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1674"><a href="#cb66-1674" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1675"><a href="#cb66-1675" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1676"><a href="#cb66-1676" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-1677"><a href="#cb66-1677" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1678"><a href="#cb66-1678" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1679"><a href="#cb66-1679" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-1680"><a href="#cb66-1680" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-1681"><a href="#cb66-1681" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1682"><a href="#cb66-1682" aria-hidden="true" tabindex="-1"></a>t_2</span>
<span id="cb66-1683"><a href="#cb66-1683" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1684"><a href="#cb66-1684" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1685"><a href="#cb66-1685" aria-hidden="true" tabindex="-1"></a>Save table 2 (XLSX and DOCX)</span>
<span id="cb66-1686"><a href="#cb66-1686" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1689"><a href="#cb66-1689" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1690"><a href="#cb66-1690" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1691"><a href="#cb66-1691" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1692"><a href="#cb66-1692" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-table-2</span></span>
<span id="cb66-1693"><a href="#cb66-1693" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1694"><a href="#cb66-1694" aria-hidden="true" tabindex="-1"></a><span class="co"># XLSX</span></span>
<span id="cb66-1695"><a href="#cb66-1695" aria-hidden="true" tabindex="-1"></a><span class="fu">write.xlsx</span>(d_t_2, </span>
<span id="cb66-1696"><a href="#cb66-1696" aria-hidden="true" tabindex="-1"></a>           <span class="st">'..//Tabelas//Paper_Table_2_Dataset.xlsx'</span>)</span>
<span id="cb66-1697"><a href="#cb66-1697" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1698"><a href="#cb66-1698" aria-hidden="true" tabindex="-1"></a><span class="co"># DOCX</span></span>
<span id="cb66-1699"><a href="#cb66-1699" aria-hidden="true" tabindex="-1"></a>path <span class="ot">&lt;-</span> <span class="st">'..//Tabelas/Paper_Table_2_R.docx'</span></span>
<span id="cb66-1700"><a href="#cb66-1700" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb66-1701"><a href="#cb66-1701" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_2)</span>
<span id="cb66-1702"><a href="#cb66-1702" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span>
<span id="cb66-1703"><a href="#cb66-1703" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1704"><a href="#cb66-1704" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1705"><a href="#cb66-1705" aria-hidden="true" tabindex="-1"></a><span class="fu">## Transfers and Reelection</span></span>
<span id="cb66-1706"><a href="#cb66-1706" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1707"><a href="#cb66-1707" aria-hidden="true" tabindex="-1"></a>::: callout-note</span>
<span id="cb66-1708"><a href="#cb66-1708" aria-hidden="true" tabindex="-1"></a>In this work, we consider only funding originating from public revenues.</span>
<span id="cb66-1709"><a href="#cb66-1709" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1710"><a href="#cb66-1710" aria-hidden="true" tabindex="-1"></a>Only the transformed variables presented in the tables below were translated; the others were kept in Portuguese.</span>
<span id="cb66-1711"><a href="#cb66-1711" aria-hidden="true" tabindex="-1"></a>:::</span>
<span id="cb66-1712"><a href="#cb66-1712" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1713"><a href="#cb66-1713" aria-hidden="true" tabindex="-1"></a><span class="fu">### Create dataset for Tables 3 and 4</span></span>
<span id="cb66-1714"><a href="#cb66-1714" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1717"><a href="#cb66-1717" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1718"><a href="#cb66-1718" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1719"><a href="#cb66-1719" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1720"><a href="#cb66-1720" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: create-data-tables-3-4</span></span>
<span id="cb66-1721"><a href="#cb66-1721" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1722"><a href="#cb66-1722" aria-hidden="true" tabindex="-1"></a>d_tables_3_4 <span class="ot">&lt;-</span> receitas_publicas <span class="sc">%&gt;%</span> </span>
<span id="cb66-1723"><a href="#cb66-1723" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(</span>
<span id="cb66-1724"><a href="#cb66-1724" aria-hidden="true" tabindex="-1"></a>    cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"White"</span>, <span class="st">"Black"</span>),</span>
<span id="cb66-1725"><a href="#cb66-1725" aria-hidden="true" tabindex="-1"></a>    genero <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"Men"</span>, <span class="st">"Women"</span>),</span>
<span id="cb66-1726"><a href="#cb66-1726" aria-hidden="true" tabindex="-1"></a>    cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'DEPUTADO FEDERAL'</span>,</span>
<span id="cb66-1727"><a href="#cb66-1727" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO DISTRITAL'</span>,</span>
<span id="cb66-1728"><a href="#cb66-1728" aria-hidden="true" tabindex="-1"></a>                 <span class="st">'DEPUTADO ESTADUAL'</span>)</span>
<span id="cb66-1729"><a href="#cb66-1729" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">%&gt;%</span></span>
<span id="cb66-1730"><a href="#cb66-1730" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-1731"><a href="#cb66-1731" aria-hidden="true" tabindex="-1"></a>    <span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb66-1732"><a href="#cb66-1732" aria-hidden="true" tabindex="-1"></a>    <span class="at">race_color =</span> cor_raca,</span>
<span id="cb66-1733"><a href="#cb66-1733" aria-hidden="true" tabindex="-1"></a>    <span class="at">gender =</span> genero,</span>
<span id="cb66-1734"><a href="#cb66-1734" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">ifelse</span>(cargo <span class="sc">==</span> <span class="st">"DEPUTADO DISTRITAL"</span>, </span>
<span id="cb66-1735"><a href="#cb66-1735" aria-hidden="true" tabindex="-1"></a>                      <span class="st">"DEPUTADO ESTADUAL"</span>, </span>
<span id="cb66-1736"><a href="#cb66-1736" aria-hidden="true" tabindex="-1"></a>                      cargo),</span>
<span id="cb66-1737"><a href="#cb66-1737" aria-hidden="true" tabindex="-1"></a>    <span class="at">dispute_status =</span> <span class="fu">ifelse</span>(reeleicao <span class="sc">==</span> <span class="st">"Reelection"</span>,</span>
<span id="cb66-1738"><a href="#cb66-1738" aria-hidden="true" tabindex="-1"></a>                            <span class="st">"Incumbent"</span>,</span>
<span id="cb66-1739"><a href="#cb66-1739" aria-hidden="true" tabindex="-1"></a>                            reeleicao)</span>
<span id="cb66-1740"><a href="#cb66-1740" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">%&gt;%</span></span>
<span id="cb66-1741"><a href="#cb66-1741" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span><span class="fu">c</span>(ano_eleicao, cor_raca, genero, cargo, reeleicao)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1742"><a href="#cb66-1742" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(position, year_election, gender, race_color, dispute_status) <span class="sc">%&gt;%</span></span>
<span id="cb66-1743"><a href="#cb66-1743" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(</span>
<span id="cb66-1744"><a href="#cb66-1744" aria-hidden="true" tabindex="-1"></a>    <span class="at">total_receita_grupo =</span> <span class="fu">sum</span>(rec_cand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb66-1745"><a href="#cb66-1745" aria-hidden="true" tabindex="-1"></a>    <span class="at">qtd_cand_grupo =</span> <span class="fu">n_distinct</span>(cpf_candidato),</span>
<span id="cb66-1746"><a href="#cb66-1746" aria-hidden="true" tabindex="-1"></a>    <span class="at">.groups =</span> <span class="st">"drop"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-1747"><a href="#cb66-1747" aria-hidden="true" tabindex="-1"></a>  <span class="fu">ungroup</span>() <span class="sc">%&gt;%</span></span>
<span id="cb66-1748"><a href="#cb66-1748" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(position, year_election) <span class="sc">%&gt;%</span></span>
<span id="cb66-1749"><a href="#cb66-1749" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-1750"><a href="#cb66-1750" aria-hidden="true" tabindex="-1"></a>    <span class="at">prc_rvn =</span> total_receita_grupo <span class="sc">/</span> <span class="fu">sum</span>(total_receita_grupo, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb66-1751"><a href="#cb66-1751" aria-hidden="true" tabindex="-1"></a>    <span class="at">prc_cnd =</span> qtd_cand_grupo <span class="sc">/</span> <span class="fu">sum</span>(qtd_cand_grupo, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb66-1752"><a href="#cb66-1752" aria-hidden="true" tabindex="-1"></a>    <span class="at">avg_rvn =</span> total_receita_grupo <span class="sc">/</span>  qtd_cand_grupo) <span class="sc">%&gt;%</span></span>
<span id="cb66-1753"><a href="#cb66-1753" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(</span>
<span id="cb66-1754"><a href="#cb66-1754" aria-hidden="true" tabindex="-1"></a>    position, year_election, gender, race_color, dispute_status, </span>
<span id="cb66-1755"><a href="#cb66-1755" aria-hidden="true" tabindex="-1"></a>    prc_cnd, prc_rvn, avg_rvn)</span>
<span id="cb66-1756"><a href="#cb66-1756" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1757"><a href="#cb66-1757" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(d_tables_3_4)</span>
<span id="cb66-1758"><a href="#cb66-1758" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1759"><a href="#cb66-1759" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1760"><a href="#cb66-1760" aria-hidden="true" tabindex="-1"></a><span class="fu">### Table 3 - Proportion and average funds of candidates for federal deputy by gender, race and dispute status (challenger x incumbent)</span></span>
<span id="cb66-1761"><a href="#cb66-1761" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1762"><a href="#cb66-1762" aria-hidden="true" tabindex="-1"></a>Plot Table 3 - panel "a": Federal Deputy - 2018</span>
<span id="cb66-1763"><a href="#cb66-1763" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1766"><a href="#cb66-1766" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1767"><a href="#cb66-1767" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1768"><a href="#cb66-1768" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1769"><a href="#cb66-1769" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-3-a</span></span>
<span id="cb66-1770"><a href="#cb66-1770" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1771"><a href="#cb66-1771" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2018</span></span>
<span id="cb66-1772"><a href="#cb66-1772" aria-hidden="true" tabindex="-1"></a>t_3_a <span class="ot">&lt;-</span> d_tables_3_4 <span class="sc">%&gt;%</span></span>
<span id="cb66-1773"><a href="#cb66-1773" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb66-1774"><a href="#cb66-1774" aria-hidden="true" tabindex="-1"></a>         position <span class="sc">==</span> <span class="st">"DEPUTADO FEDERAL"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-1775"><a href="#cb66-1775" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb66-1776"><a href="#cb66-1776" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb66-1777"><a href="#cb66-1777" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="st">"dispute_status"</span>,</span>
<span id="cb66-1778"><a href="#cb66-1778" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Candidate (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_cnd, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb66-1779"><a href="#cb66-1779" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_rvn, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb66-1780"><a href="#cb66-1780" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(avg_rvn,</span>
<span id="cb66-1781"><a href="#cb66-1781" aria-hidden="true" tabindex="-1"></a>                                                 <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb66-1782"><a href="#cb66-1782" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1783"><a href="#cb66-1783" aria-hidden="true" tabindex="-1"></a>t_3_a <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_3_a) <span class="sc">%&gt;%</span></span>
<span id="cb66-1784"><a href="#cb66-1784" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-1785"><a href="#cb66-1785" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-1786"><a href="#cb66-1786" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-1787"><a href="#cb66-1787" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb66-1788"><a href="#cb66-1788" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-1789"><a href="#cb66-1789" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb66-1790"><a href="#cb66-1790" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-1791"><a href="#cb66-1791" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb66-1792"><a href="#cb66-1792" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb66-1793"><a href="#cb66-1793" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1794"><a href="#cb66-1794" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1795"><a href="#cb66-1795" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1796"><a href="#cb66-1796" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1797"><a href="#cb66-1797" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1798"><a href="#cb66-1798" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-1799"><a href="#cb66-1799" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1800"><a href="#cb66-1800" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1801"><a href="#cb66-1801" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-1802"><a href="#cb66-1802" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-1803"><a href="#cb66-1803" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1804"><a href="#cb66-1804" aria-hidden="true" tabindex="-1"></a>t_3_a</span>
<span id="cb66-1805"><a href="#cb66-1805" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1806"><a href="#cb66-1806" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1807"><a href="#cb66-1807" aria-hidden="true" tabindex="-1"></a>Format Table 3 - panel "b": Federal Deputy - 2022</span>
<span id="cb66-1808"><a href="#cb66-1808" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1811"><a href="#cb66-1811" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1812"><a href="#cb66-1812" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-3-b</span></span>
<span id="cb66-1813"><a href="#cb66-1813" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1814"><a href="#cb66-1814" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1815"><a href="#cb66-1815" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1816"><a href="#cb66-1816" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2022</span></span>
<span id="cb66-1817"><a href="#cb66-1817" aria-hidden="true" tabindex="-1"></a>t_3_b <span class="ot">&lt;-</span> d_tables_3_4 <span class="sc">%&gt;%</span></span>
<span id="cb66-1818"><a href="#cb66-1818" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb66-1819"><a href="#cb66-1819" aria-hidden="true" tabindex="-1"></a>         position <span class="sc">==</span> <span class="st">"DEPUTADO FEDERAL"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-1820"><a href="#cb66-1820" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb66-1821"><a href="#cb66-1821" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb66-1822"><a href="#cb66-1822" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="st">"dispute_status"</span>,</span>
<span id="cb66-1823"><a href="#cb66-1823" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Candidate (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_cnd, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb66-1824"><a href="#cb66-1824" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_rvn, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb66-1825"><a href="#cb66-1825" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(avg_rvn,</span>
<span id="cb66-1826"><a href="#cb66-1826" aria-hidden="true" tabindex="-1"></a>                                                 <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb66-1827"><a href="#cb66-1827" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1828"><a href="#cb66-1828" aria-hidden="true" tabindex="-1"></a>t_3_b <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_3_b) <span class="sc">%&gt;%</span></span>
<span id="cb66-1829"><a href="#cb66-1829" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-1830"><a href="#cb66-1830" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-1831"><a href="#cb66-1831" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-1832"><a href="#cb66-1832" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb66-1833"><a href="#cb66-1833" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-1834"><a href="#cb66-1834" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb66-1835"><a href="#cb66-1835" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-1836"><a href="#cb66-1836" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb66-1837"><a href="#cb66-1837" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb66-1838"><a href="#cb66-1838" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1839"><a href="#cb66-1839" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1840"><a href="#cb66-1840" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1841"><a href="#cb66-1841" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1842"><a href="#cb66-1842" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1843"><a href="#cb66-1843" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-1844"><a href="#cb66-1844" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1845"><a href="#cb66-1845" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1846"><a href="#cb66-1846" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-1847"><a href="#cb66-1847" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-1848"><a href="#cb66-1848" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1849"><a href="#cb66-1849" aria-hidden="true" tabindex="-1"></a>t_3_b</span>
<span id="cb66-1850"><a href="#cb66-1850" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1851"><a href="#cb66-1851" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1852"><a href="#cb66-1852" aria-hidden="true" tabindex="-1"></a>Save table 3, panels "a" and "b", in DOCX format</span>
<span id="cb66-1853"><a href="#cb66-1853" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1856"><a href="#cb66-1856" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1857"><a href="#cb66-1857" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1858"><a href="#cb66-1858" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1859"><a href="#cb66-1859" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-table-3</span></span>
<span id="cb66-1860"><a href="#cb66-1860" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1861"><a href="#cb66-1861" aria-hidden="true" tabindex="-1"></a>path <span class="ot">&lt;-</span> <span class="st">'..//Tabelas/Paper_Table_3_R.docx'</span></span>
<span id="cb66-1862"><a href="#cb66-1862" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1863"><a href="#cb66-1863" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb66-1864"><a href="#cb66-1864" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value=</span>t_3_a)</span>
<span id="cb66-1865"><a href="#cb66-1865" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value=</span>t_3_b)</span>
<span id="cb66-1866"><a href="#cb66-1866" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span>
<span id="cb66-1867"><a href="#cb66-1867" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1868"><a href="#cb66-1868" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1869"><a href="#cb66-1869" aria-hidden="true" tabindex="-1"></a><span class="fu">### Table 4 - Proportion and average funds of candidates for state deputy by gender, race and dispute status (challenger x incumbent)</span></span>
<span id="cb66-1870"><a href="#cb66-1870" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1871"><a href="#cb66-1871" aria-hidden="true" tabindex="-1"></a>Plot Table 4 - panel "a": State Deputy - 2018</span>
<span id="cb66-1872"><a href="#cb66-1872" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1875"><a href="#cb66-1875" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1876"><a href="#cb66-1876" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1877"><a href="#cb66-1877" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1878"><a href="#cb66-1878" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-4-a</span></span>
<span id="cb66-1879"><a href="#cb66-1879" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1880"><a href="#cb66-1880" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2018</span></span>
<span id="cb66-1881"><a href="#cb66-1881" aria-hidden="true" tabindex="-1"></a>t_4_a <span class="ot">&lt;-</span> d_tables_3_4 <span class="sc">%&gt;%</span></span>
<span id="cb66-1882"><a href="#cb66-1882" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb66-1883"><a href="#cb66-1883" aria-hidden="true" tabindex="-1"></a>         position <span class="sc">==</span> <span class="st">"DEPUTADO ESTADUAL"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-1884"><a href="#cb66-1884" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb66-1885"><a href="#cb66-1885" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb66-1886"><a href="#cb66-1886" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="st">"dispute_status"</span>,</span>
<span id="cb66-1887"><a href="#cb66-1887" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Candidate (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_cnd, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb66-1888"><a href="#cb66-1888" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_rvn, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb66-1889"><a href="#cb66-1889" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(avg_rvn,</span>
<span id="cb66-1890"><a href="#cb66-1890" aria-hidden="true" tabindex="-1"></a>                                                 <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb66-1891"><a href="#cb66-1891" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1892"><a href="#cb66-1892" aria-hidden="true" tabindex="-1"></a>t_4_a <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_4_a) <span class="sc">%&gt;%</span></span>
<span id="cb66-1893"><a href="#cb66-1893" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-1894"><a href="#cb66-1894" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-1895"><a href="#cb66-1895" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-1896"><a href="#cb66-1896" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb66-1897"><a href="#cb66-1897" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-1898"><a href="#cb66-1898" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb66-1899"><a href="#cb66-1899" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-1900"><a href="#cb66-1900" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb66-1901"><a href="#cb66-1901" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb66-1902"><a href="#cb66-1902" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1903"><a href="#cb66-1903" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1904"><a href="#cb66-1904" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1905"><a href="#cb66-1905" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1906"><a href="#cb66-1906" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1907"><a href="#cb66-1907" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-1908"><a href="#cb66-1908" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1909"><a href="#cb66-1909" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1910"><a href="#cb66-1910" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-1911"><a href="#cb66-1911" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-1912"><a href="#cb66-1912" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1913"><a href="#cb66-1913" aria-hidden="true" tabindex="-1"></a>t_4_a</span>
<span id="cb66-1914"><a href="#cb66-1914" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1915"><a href="#cb66-1915" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1916"><a href="#cb66-1916" aria-hidden="true" tabindex="-1"></a>Plot Table 4 - panel "a": State Deputy - 2022</span>
<span id="cb66-1917"><a href="#cb66-1917" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1920"><a href="#cb66-1920" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1921"><a href="#cb66-1921" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1922"><a href="#cb66-1922" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1923"><a href="#cb66-1923" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-4-b</span></span>
<span id="cb66-1924"><a href="#cb66-1924" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1925"><a href="#cb66-1925" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2022</span></span>
<span id="cb66-1926"><a href="#cb66-1926" aria-hidden="true" tabindex="-1"></a>t_4_b <span class="ot">&lt;-</span> d_tables_3_4 <span class="sc">%&gt;%</span></span>
<span id="cb66-1927"><a href="#cb66-1927" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb66-1928"><a href="#cb66-1928" aria-hidden="true" tabindex="-1"></a>         position <span class="sc">==</span> <span class="st">"DEPUTADO ESTADUAL"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb66-1929"><a href="#cb66-1929" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb66-1930"><a href="#cb66-1930" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb66-1931"><a href="#cb66-1931" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="st">"dispute_status"</span>,</span>
<span id="cb66-1932"><a href="#cb66-1932" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Candidate (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_cnd, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb66-1933"><a href="#cb66-1933" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue (%)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(prc_rvn, <span class="at">formatter =</span> fmt_pct)),</span>
<span id="cb66-1934"><a href="#cb66-1934" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(<span class="fu">as_chunk</span>(avg_rvn,</span>
<span id="cb66-1935"><a href="#cb66-1935" aria-hidden="true" tabindex="-1"></a>                                                 <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb66-1936"><a href="#cb66-1936" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1937"><a href="#cb66-1937" aria-hidden="true" tabindex="-1"></a>t_4_b <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_4_b) <span class="sc">%&gt;%</span></span>
<span id="cb66-1938"><a href="#cb66-1938" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-1939"><a href="#cb66-1939" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-1940"><a href="#cb66-1940" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-1941"><a href="#cb66-1941" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb66-1942"><a href="#cb66-1942" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-1943"><a href="#cb66-1943" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb66-1944"><a href="#cb66-1944" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-1945"><a href="#cb66-1945" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb66-1946"><a href="#cb66-1946" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb66-1947"><a href="#cb66-1947" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1948"><a href="#cb66-1948" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1949"><a href="#cb66-1949" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1950"><a href="#cb66-1950" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1951"><a href="#cb66-1951" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1952"><a href="#cb66-1952" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-1953"><a href="#cb66-1953" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-1954"><a href="#cb66-1954" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-1955"><a href="#cb66-1955" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-1956"><a href="#cb66-1956" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-1957"><a href="#cb66-1957" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1958"><a href="#cb66-1958" aria-hidden="true" tabindex="-1"></a>t_4_b</span>
<span id="cb66-1959"><a href="#cb66-1959" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1960"><a href="#cb66-1960" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1961"><a href="#cb66-1961" aria-hidden="true" tabindex="-1"></a>Save table 4, panels "a" and "b", in DOCX format</span>
<span id="cb66-1962"><a href="#cb66-1962" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1965"><a href="#cb66-1965" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1966"><a href="#cb66-1966" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-1967"><a href="#cb66-1967" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-1968"><a href="#cb66-1968" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-table-4</span></span>
<span id="cb66-1969"><a href="#cb66-1969" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1970"><a href="#cb66-1970" aria-hidden="true" tabindex="-1"></a>path <span class="ot">=</span> <span class="st">'..//Tabelas/Paper_Table_4_R.docx'</span></span>
<span id="cb66-1971"><a href="#cb66-1971" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1972"><a href="#cb66-1972" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb66-1973"><a href="#cb66-1973" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_4_a)</span>
<span id="cb66-1974"><a href="#cb66-1974" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_4_b)</span>
<span id="cb66-1975"><a href="#cb66-1975" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span>
<span id="cb66-1976"><a href="#cb66-1976" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-1977"><a href="#cb66-1977" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1978"><a href="#cb66-1978" aria-hidden="true" tabindex="-1"></a><span class="fu">## Appendix A - Table 1 - Public resource transfers between candidate providers, by gender and race</span></span>
<span id="cb66-1979"><a href="#cb66-1979" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1980"><a href="#cb66-1980" aria-hidden="true" tabindex="-1"></a>Create dataset for Table A1</span>
<span id="cb66-1981"><a href="#cb66-1981" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-1984"><a href="#cb66-1984" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-1985"><a href="#cb66-1985" aria-hidden="true" tabindex="-1"></a>d_table_a1 <span class="ot">&lt;-</span> receitas_publicas_especie_agr <span class="sc">%&gt;%</span></span>
<span id="cb66-1986"><a href="#cb66-1986" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(genero <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'Men'</span>, <span class="st">'Women'</span>),</span>
<span id="cb66-1987"><a href="#cb66-1987" aria-hidden="true" tabindex="-1"></a>         cor_raca <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">'White'</span>, <span class="st">'Black'</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1988"><a href="#cb66-1988" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-1989"><a href="#cb66-1989" aria-hidden="true" tabindex="-1"></a>    <span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb66-1990"><a href="#cb66-1990" aria-hidden="true" tabindex="-1"></a>    <span class="at">race_color =</span> cor_raca,</span>
<span id="cb66-1991"><a href="#cb66-1991" aria-hidden="true" tabindex="-1"></a>    <span class="at">gender =</span> genero,</span>
<span id="cb66-1992"><a href="#cb66-1992" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">case_when</span>(</span>
<span id="cb66-1993"><a href="#cb66-1993" aria-hidden="true" tabindex="-1"></a>      cargo <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"DEPUTADO DISTRITAL"</span>, </span>
<span id="cb66-1994"><a href="#cb66-1994" aria-hidden="true" tabindex="-1"></a>                   <span class="st">"DEPUTADO ESTADUAL"</span>) <span class="sc">~</span> <span class="st">'State Deputy'</span>,</span>
<span id="cb66-1995"><a href="#cb66-1995" aria-hidden="true" tabindex="-1"></a>      cargo <span class="sc">==</span> <span class="st">'DEPUTADO FEDERAL'</span> <span class="sc">~</span> <span class="st">'Federal Deputy'</span>),</span>
<span id="cb66-1996"><a href="#cb66-1996" aria-hidden="true" tabindex="-1"></a>    <span class="at">rvn_kind =</span> especie_receita) <span class="sc">%&gt;%</span></span>
<span id="cb66-1997"><a href="#cb66-1997" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span><span class="fu">c</span>(ano_eleicao, cor_raca, genero, cargo, especie_receita)) <span class="sc">%&gt;%</span></span>
<span id="cb66-1998"><a href="#cb66-1998" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(year_election, position, gender, race_color,</span>
<span id="cb66-1999"><a href="#cb66-1999" aria-hidden="true" tabindex="-1"></a>           rvn_kind) <span class="sc">%&gt;%</span></span>
<span id="cb66-2000"><a href="#cb66-2000" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(</span>
<span id="cb66-2001"><a href="#cb66-2001" aria-hidden="true" tabindex="-1"></a>    <span class="at">rvn_amount =</span> <span class="fu">sum</span>(total_rec_ano_cargo_genero_cor_especie, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb66-2002"><a href="#cb66-2002" aria-hidden="true" tabindex="-1"></a>    <span class="at">.groups =</span> <span class="st">"drop"</span>)</span>
<span id="cb66-2003"><a href="#cb66-2003" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2004"><a href="#cb66-2004" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(d_table_a1)</span>
<span id="cb66-2005"><a href="#cb66-2005" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2006"><a href="#cb66-2006" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2007"><a href="#cb66-2007" aria-hidden="true" tabindex="-1"></a>Plot Table A1</span>
<span id="cb66-2008"><a href="#cb66-2008" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2011"><a href="#cb66-2011" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2012"><a href="#cb66-2012" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2013"><a href="#cb66-2013" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2014"><a href="#cb66-2014" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-a-1</span></span>
<span id="cb66-2015"><a href="#cb66-2015" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2016"><a href="#cb66-2016" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2018</span></span>
<span id="cb66-2017"><a href="#cb66-2017" aria-hidden="true" tabindex="-1"></a>t_a1_a <span class="ot">&lt;-</span> d_table_a1 <span class="sc">|&gt;</span></span>
<span id="cb66-2018"><a href="#cb66-2018" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election) <span class="sc">|&gt;</span></span>
<span id="cb66-2019"><a href="#cb66-2019" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb66-2020"><a href="#cb66-2020" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"position"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb66-2021"><a href="#cb66-2021" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"rvn_kind"</span>),</span>
<span id="cb66-2022"><a href="#cb66-2022" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue amount (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2023"><a href="#cb66-2023" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(rvn_amount, <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb66-2024"><a href="#cb66-2024" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2025"><a href="#cb66-2025" aria-hidden="true" tabindex="-1"></a>t_a1_a <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_a1_a) <span class="sc">|&gt;</span></span>
<span id="cb66-2026"><a href="#cb66-2026" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-2027"><a href="#cb66-2027" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-2028"><a href="#cb66-2028" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-2029"><a href="#cb66-2029" aria-hidden="true" tabindex="-1"></a>      <span class="st">"position"</span> <span class="ot">=</span> <span class="st">"Position"</span>,</span>
<span id="cb66-2030"><a href="#cb66-2030" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb66-2031"><a href="#cb66-2031" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-2032"><a href="#cb66-2032" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb66-2033"><a href="#cb66-2033" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2034"><a href="#cb66-2034" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb66-2035"><a href="#cb66-2035" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb66-2036"><a href="#cb66-2036" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2037"><a href="#cb66-2037" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2038"><a href="#cb66-2038" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2039"><a href="#cb66-2039" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2040"><a href="#cb66-2040" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2041"><a href="#cb66-2041" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-2042"><a href="#cb66-2042" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2043"><a href="#cb66-2043" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2044"><a href="#cb66-2044" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-2045"><a href="#cb66-2045" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-2046"><a href="#cb66-2046" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2047"><a href="#cb66-2047" aria-hidden="true" tabindex="-1"></a>t_a1_a</span>
<span id="cb66-2048"><a href="#cb66-2048" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2049"><a href="#cb66-2049" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2052"><a href="#cb66-2052" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2053"><a href="#cb66-2053" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2054"><a href="#cb66-2054" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2055"><a href="#cb66-2055" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-a-1-b</span></span>
<span id="cb66-2056"><a href="#cb66-2056" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2057"><a href="#cb66-2057" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2022</span></span>
<span id="cb66-2058"><a href="#cb66-2058" aria-hidden="true" tabindex="-1"></a>t_a1_b <span class="ot">&lt;-</span> d_table_a1 <span class="sc">|&gt;</span></span>
<span id="cb66-2059"><a href="#cb66-2059" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election) <span class="sc">|&gt;</span></span>
<span id="cb66-2060"><a href="#cb66-2060" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb66-2061"><a href="#cb66-2061" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"position"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb66-2062"><a href="#cb66-2062" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>, <span class="st">"rvn_kind"</span>),</span>
<span id="cb66-2063"><a href="#cb66-2063" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue amount (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2064"><a href="#cb66-2064" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(rvn_amount, <span class="at">formatter =</span> fmt_int)))</span>
<span id="cb66-2065"><a href="#cb66-2065" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2066"><a href="#cb66-2066" aria-hidden="true" tabindex="-1"></a>t_a1_b <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_a1_b) <span class="sc">|&gt;</span></span>
<span id="cb66-2067"><a href="#cb66-2067" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-2068"><a href="#cb66-2068" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-2069"><a href="#cb66-2069" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-2070"><a href="#cb66-2070" aria-hidden="true" tabindex="-1"></a>      <span class="st">"position"</span> <span class="ot">=</span> <span class="st">"Position"</span>,</span>
<span id="cb66-2071"><a href="#cb66-2071" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb66-2072"><a href="#cb66-2072" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-2073"><a href="#cb66-2073" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb66-2074"><a href="#cb66-2074" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2075"><a href="#cb66-2075" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb66-2076"><a href="#cb66-2076" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">10</span>,</span>
<span id="cb66-2077"><a href="#cb66-2077" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">FALSE</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2078"><a href="#cb66-2078" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2079"><a href="#cb66-2079" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.8</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2080"><a href="#cb66-2080" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2081"><a href="#cb66-2081" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2082"><a href="#cb66-2082" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-2083"><a href="#cb66-2083" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2084"><a href="#cb66-2084" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2085"><a href="#cb66-2085" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-2086"><a href="#cb66-2086" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-2087"><a href="#cb66-2087" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2088"><a href="#cb66-2088" aria-hidden="true" tabindex="-1"></a>t_a1_b</span>
<span id="cb66-2089"><a href="#cb66-2089" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2090"><a href="#cb66-2090" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2091"><a href="#cb66-2091" aria-hidden="true" tabindex="-1"></a>Save table A-1</span>
<span id="cb66-2092"><a href="#cb66-2092" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2095"><a href="#cb66-2095" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2096"><a href="#cb66-2096" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2097"><a href="#cb66-2097" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2098"><a href="#cb66-2098" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-table-a-1</span></span>
<span id="cb66-2099"><a href="#cb66-2099" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2100"><a href="#cb66-2100" aria-hidden="true" tabindex="-1"></a>path <span class="ot">=</span> <span class="st">'..//Tabelas/Paper_Table_A-1_R.docx'</span></span>
<span id="cb66-2101"><a href="#cb66-2101" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2102"><a href="#cb66-2102" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb66-2103"><a href="#cb66-2103" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_a1_a)</span>
<span id="cb66-2104"><a href="#cb66-2104" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_a1_b)</span>
<span id="cb66-2105"><a href="#cb66-2105" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span>
<span id="cb66-2106"><a href="#cb66-2106" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2107"><a href="#cb66-2107" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2108"><a href="#cb66-2108" aria-hidden="true" tabindex="-1"></a><span class="fu">## Appendix B</span></span>
<span id="cb66-2109"><a href="#cb66-2109" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2110"><a href="#cb66-2110" aria-hidden="true" tabindex="-1"></a><span class="fu">### Table B-1 - Average public resource of federal deputies by week of spending, gender and race</span></span>
<span id="cb66-2111"><a href="#cb66-2111" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2112"><a href="#cb66-2112" aria-hidden="true" tabindex="-1"></a>Create datasets for table B-1 (Federal Deputy)</span>
<span id="cb66-2113"><a href="#cb66-2113" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2116"><a href="#cb66-2116" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2117"><a href="#cb66-2117" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2118"><a href="#cb66-2118" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2119"><a href="#cb66-2119" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: create-data-table-b-1</span></span>
<span id="cb66-2120"><a href="#cb66-2120" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2121"><a href="#cb66-2121" aria-hidden="true" tabindex="-1"></a>d_table_b1 <span class="ot">&lt;-</span> g3_data <span class="sc">%&gt;%</span></span>
<span id="cb66-2122"><a href="#cb66-2122" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-2123"><a href="#cb66-2123" aria-hidden="true" tabindex="-1"></a>    <span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb66-2124"><a href="#cb66-2124" aria-hidden="true" tabindex="-1"></a>    <span class="at">week_revenue =</span> semana_receita,</span>
<span id="cb66-2125"><a href="#cb66-2125" aria-hidden="true" tabindex="-1"></a>    <span class="at">race_color =</span> cor_raca,</span>
<span id="cb66-2126"><a href="#cb66-2126" aria-hidden="true" tabindex="-1"></a>    <span class="at">gender =</span> genero,</span>
<span id="cb66-2127"><a href="#cb66-2127" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> cargo) <span class="sc">%&gt;%</span></span>
<span id="cb66-2128"><a href="#cb66-2128" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(year_election, position, week_revenue, </span>
<span id="cb66-2129"><a href="#cb66-2129" aria-hidden="true" tabindex="-1"></a>           gender, race_color) <span class="sc">%&gt;%</span></span>
<span id="cb66-2130"><a href="#cb66-2130" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">avg_public_revenue =</span> <span class="fu">mean</span>(media_receitas_genero_cor)) <span class="sc">%&gt;%</span></span>
<span id="cb66-2131"><a href="#cb66-2131" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">avg_public_revenue =</span> <span class="fu">round</span>(avg_public_revenue, <span class="dv">2</span>))</span>
<span id="cb66-2132"><a href="#cb66-2132" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2133"><a href="#cb66-2133" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(d_table_b1)</span>
<span id="cb66-2134"><a href="#cb66-2134" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2135"><a href="#cb66-2135" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2136"><a href="#cb66-2136" aria-hidden="true" tabindex="-1"></a><span class="fu">### </span></span>
<span id="cb66-2137"><a href="#cb66-2137" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2138"><a href="#cb66-2138" aria-hidden="true" tabindex="-1"></a>Plot table B1 - panel "a" (Federal Deputy - 2018)</span>
<span id="cb66-2139"><a href="#cb66-2139" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2142"><a href="#cb66-2142" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2143"><a href="#cb66-2143" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2144"><a href="#cb66-2144" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2145"><a href="#cb66-2145" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-b1-a</span></span>
<span id="cb66-2146"><a href="#cb66-2146" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2147"><a href="#cb66-2147" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2018</span></span>
<span id="cb66-2148"><a href="#cb66-2148" aria-hidden="true" tabindex="-1"></a>min_week_revenue <span class="ot">&lt;-</span> <span class="st">'2018-08-18'</span></span>
<span id="cb66-2149"><a href="#cb66-2149" aria-hidden="true" tabindex="-1"></a>max_week_revenue <span class="ot">&lt;-</span> <span class="st">'2018-09-30'</span></span>
<span id="cb66-2150"><a href="#cb66-2150" aria-hidden="true" tabindex="-1"></a>t_b1_a <span class="ot">&lt;-</span> d_table_b1 <span class="sc">|&gt;</span></span>
<span id="cb66-2151"><a href="#cb66-2151" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb66-2152"><a href="#cb66-2152" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&gt;=</span> min_week_revenue,</span>
<span id="cb66-2153"><a href="#cb66-2153" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&lt;=</span> max_week_revenue) <span class="sc">|&gt;</span></span>
<span id="cb66-2154"><a href="#cb66-2154" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb66-2155"><a href="#cb66-2155" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"week_revenue"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb66-2156"><a href="#cb66-2156" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>),</span>
<span id="cb66-2157"><a href="#cb66-2157" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2158"><a href="#cb66-2158" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(avg_public_revenue, <span class="at">formatter =</span> fmt_dbl)))</span>
<span id="cb66-2159"><a href="#cb66-2159" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2160"><a href="#cb66-2160" aria-hidden="true" tabindex="-1"></a>t_b1_a <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_b1_a) <span class="sc">|&gt;</span></span>
<span id="cb66-2161"><a href="#cb66-2161" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-2162"><a href="#cb66-2162" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-2163"><a href="#cb66-2163" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-2164"><a href="#cb66-2164" aria-hidden="true" tabindex="-1"></a>      <span class="st">"week_revenue"</span> <span class="ot">=</span> <span class="st">"Revenue registration week "</span>,</span>
<span id="cb66-2165"><a href="#cb66-2165" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb66-2166"><a href="#cb66-2166" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-2167"><a href="#cb66-2167" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb66-2168"><a href="#cb66-2168" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2169"><a href="#cb66-2169" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb66-2170"><a href="#cb66-2170" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">6</span>,</span>
<span id="cb66-2171"><a href="#cb66-2171" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">TRUE</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2172"><a href="#cb66-2172" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2173"><a href="#cb66-2173" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.9</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2174"><a href="#cb66-2174" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2175"><a href="#cb66-2175" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2176"><a href="#cb66-2176" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-2177"><a href="#cb66-2177" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2178"><a href="#cb66-2178" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2179"><a href="#cb66-2179" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-2180"><a href="#cb66-2180" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-2181"><a href="#cb66-2181" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2182"><a href="#cb66-2182" aria-hidden="true" tabindex="-1"></a>t_b1_a</span>
<span id="cb66-2183"><a href="#cb66-2183" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2184"><a href="#cb66-2184" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2187"><a href="#cb66-2187" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2188"><a href="#cb66-2188" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2189"><a href="#cb66-2189" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2190"><a href="#cb66-2190" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-b1-b</span></span>
<span id="cb66-2191"><a href="#cb66-2191" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2192"><a href="#cb66-2192" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2022</span></span>
<span id="cb66-2193"><a href="#cb66-2193" aria-hidden="true" tabindex="-1"></a>min_week_revenue <span class="ot">&lt;-</span> <span class="st">'2022-08-21'</span></span>
<span id="cb66-2194"><a href="#cb66-2194" aria-hidden="true" tabindex="-1"></a>max_week_revenue <span class="ot">&lt;-</span> <span class="st">'2022-09-25'</span></span>
<span id="cb66-2195"><a href="#cb66-2195" aria-hidden="true" tabindex="-1"></a>t_b1_b <span class="ot">&lt;-</span> d_table_b1 <span class="sc">|&gt;</span></span>
<span id="cb66-2196"><a href="#cb66-2196" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb66-2197"><a href="#cb66-2197" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&gt;=</span> min_week_revenue,</span>
<span id="cb66-2198"><a href="#cb66-2198" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&lt;=</span> max_week_revenue) <span class="sc">|&gt;</span></span>
<span id="cb66-2199"><a href="#cb66-2199" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb66-2200"><a href="#cb66-2200" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"week_revenue"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb66-2201"><a href="#cb66-2201" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>),</span>
<span id="cb66-2202"><a href="#cb66-2202" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2203"><a href="#cb66-2203" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(avg_public_revenue, <span class="at">formatter =</span> fmt_dbl)))</span>
<span id="cb66-2204"><a href="#cb66-2204" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2205"><a href="#cb66-2205" aria-hidden="true" tabindex="-1"></a>t_b1_b <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_b1_b) <span class="sc">|&gt;</span></span>
<span id="cb66-2206"><a href="#cb66-2206" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-2207"><a href="#cb66-2207" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-2208"><a href="#cb66-2208" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-2209"><a href="#cb66-2209" aria-hidden="true" tabindex="-1"></a>      <span class="st">"week_revenue"</span> <span class="ot">=</span> <span class="st">"Revenue registration week "</span>,</span>
<span id="cb66-2210"><a href="#cb66-2210" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb66-2211"><a href="#cb66-2211" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-2212"><a href="#cb66-2212" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb66-2213"><a href="#cb66-2213" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2214"><a href="#cb66-2214" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb66-2215"><a href="#cb66-2215" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">6</span>,</span>
<span id="cb66-2216"><a href="#cb66-2216" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">TRUE</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2217"><a href="#cb66-2217" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2218"><a href="#cb66-2218" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.9</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2219"><a href="#cb66-2219" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2220"><a href="#cb66-2220" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2221"><a href="#cb66-2221" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-2222"><a href="#cb66-2222" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2223"><a href="#cb66-2223" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2224"><a href="#cb66-2224" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-2225"><a href="#cb66-2225" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-2226"><a href="#cb66-2226" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2227"><a href="#cb66-2227" aria-hidden="true" tabindex="-1"></a>t_b1_b</span>
<span id="cb66-2228"><a href="#cb66-2228" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2229"><a href="#cb66-2229" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2230"><a href="#cb66-2230" aria-hidden="true" tabindex="-1"></a>Save table B-1</span>
<span id="cb66-2231"><a href="#cb66-2231" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2234"><a href="#cb66-2234" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2235"><a href="#cb66-2235" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2236"><a href="#cb66-2236" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2237"><a href="#cb66-2237" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-table-b-1</span></span>
<span id="cb66-2238"><a href="#cb66-2238" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2239"><a href="#cb66-2239" aria-hidden="true" tabindex="-1"></a>path <span class="ot">=</span> <span class="st">'..//Tabelas/Paper_Table_B-1_R.docx'</span></span>
<span id="cb66-2240"><a href="#cb66-2240" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2241"><a href="#cb66-2241" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb66-2242"><a href="#cb66-2242" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_b1_a)</span>
<span id="cb66-2243"><a href="#cb66-2243" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_b1_b)</span>
<span id="cb66-2244"><a href="#cb66-2244" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span>
<span id="cb66-2245"><a href="#cb66-2245" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2246"><a href="#cb66-2246" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2247"><a href="#cb66-2247" aria-hidden="true" tabindex="-1"></a><span class="fu">### Table B-2 - Average public resource of state deputy by revenue registration week, gender and race</span></span>
<span id="cb66-2248"><a href="#cb66-2248" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2249"><a href="#cb66-2249" aria-hidden="true" tabindex="-1"></a>Create datasets for table B-2 (State Deputy)</span>
<span id="cb66-2250"><a href="#cb66-2250" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2253"><a href="#cb66-2253" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2254"><a href="#cb66-2254" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2255"><a href="#cb66-2255" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2256"><a href="#cb66-2256" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: create-data-table-b-2</span></span>
<span id="cb66-2257"><a href="#cb66-2257" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2258"><a href="#cb66-2258" aria-hidden="true" tabindex="-1"></a>d_table_b2 <span class="ot">&lt;-</span> g4_data <span class="sc">%&gt;%</span></span>
<span id="cb66-2259"><a href="#cb66-2259" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb66-2260"><a href="#cb66-2260" aria-hidden="true" tabindex="-1"></a>    <span class="at">year_election =</span> ano_eleicao,</span>
<span id="cb66-2261"><a href="#cb66-2261" aria-hidden="true" tabindex="-1"></a>    <span class="at">week_revenue =</span> semana_receita,</span>
<span id="cb66-2262"><a href="#cb66-2262" aria-hidden="true" tabindex="-1"></a>    <span class="at">race_color =</span> cor_raca,</span>
<span id="cb66-2263"><a href="#cb66-2263" aria-hidden="true" tabindex="-1"></a>    <span class="at">gender =</span> genero,</span>
<span id="cb66-2264"><a href="#cb66-2264" aria-hidden="true" tabindex="-1"></a>    <span class="at">position =</span> <span class="fu">ifelse</span>(</span>
<span id="cb66-2265"><a href="#cb66-2265" aria-hidden="true" tabindex="-1"></a>      cargo <span class="sc">==</span> <span class="st">"DEPUTADO DISTRITAL"</span> <span class="sc">|</span> cargo <span class="sc">==</span> <span class="st">"DEPUTADO ESTADUAL"</span>, </span>
<span id="cb66-2266"><a href="#cb66-2266" aria-hidden="true" tabindex="-1"></a>      <span class="st">"State Deputy"</span>, </span>
<span id="cb66-2267"><a href="#cb66-2267" aria-hidden="true" tabindex="-1"></a>      cargo)) <span class="sc">%&gt;%</span></span>
<span id="cb66-2268"><a href="#cb66-2268" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(year_election, position, week_revenue, </span>
<span id="cb66-2269"><a href="#cb66-2269" aria-hidden="true" tabindex="-1"></a>           gender, race_color) <span class="sc">%&gt;%</span></span>
<span id="cb66-2270"><a href="#cb66-2270" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">avg_public_revenue =</span> <span class="fu">mean</span>(media_receitas_genero_cor)) <span class="sc">%&gt;%</span></span>
<span id="cb66-2271"><a href="#cb66-2271" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">avg_public_revenue =</span> <span class="fu">round</span>(avg_public_revenue, <span class="dv">2</span>))</span>
<span id="cb66-2272"><a href="#cb66-2272" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2273"><a href="#cb66-2273" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(d_table_b2)</span>
<span id="cb66-2274"><a href="#cb66-2274" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2275"><a href="#cb66-2275" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2276"><a href="#cb66-2276" aria-hidden="true" tabindex="-1"></a>Plot table B2 - panel "a" (State Deputy - 2018)</span>
<span id="cb66-2277"><a href="#cb66-2277" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2280"><a href="#cb66-2280" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2281"><a href="#cb66-2281" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2282"><a href="#cb66-2282" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2283"><a href="#cb66-2283" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-b2-a</span></span>
<span id="cb66-2284"><a href="#cb66-2284" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2285"><a href="#cb66-2285" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2018</span></span>
<span id="cb66-2286"><a href="#cb66-2286" aria-hidden="true" tabindex="-1"></a>min_week_revenue <span class="ot">&lt;-</span> <span class="st">'2018-08-18'</span></span>
<span id="cb66-2287"><a href="#cb66-2287" aria-hidden="true" tabindex="-1"></a>max_week_revenue <span class="ot">&lt;-</span> <span class="st">'2018-09-30'</span></span>
<span id="cb66-2288"><a href="#cb66-2288" aria-hidden="true" tabindex="-1"></a>t_b2_a <span class="ot">&lt;-</span> d_table_b2 <span class="sc">|&gt;</span></span>
<span id="cb66-2289"><a href="#cb66-2289" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb66-2290"><a href="#cb66-2290" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&gt;=</span> min_week_revenue,</span>
<span id="cb66-2291"><a href="#cb66-2291" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&lt;=</span> max_week_revenue) <span class="sc">|&gt;</span></span>
<span id="cb66-2292"><a href="#cb66-2292" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb66-2293"><a href="#cb66-2293" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"week_revenue"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb66-2294"><a href="#cb66-2294" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>),</span>
<span id="cb66-2295"><a href="#cb66-2295" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2296"><a href="#cb66-2296" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(avg_public_revenue, <span class="at">formatter =</span> fmt_dbl)))</span>
<span id="cb66-2297"><a href="#cb66-2297" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2298"><a href="#cb66-2298" aria-hidden="true" tabindex="-1"></a>t_b2_a <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_b2_a) <span class="sc">|&gt;</span></span>
<span id="cb66-2299"><a href="#cb66-2299" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-2300"><a href="#cb66-2300" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-2301"><a href="#cb66-2301" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-2302"><a href="#cb66-2302" aria-hidden="true" tabindex="-1"></a>      <span class="st">"week_revenue"</span> <span class="ot">=</span> <span class="st">"Revenue registration week"</span>,</span>
<span id="cb66-2303"><a href="#cb66-2303" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb66-2304"><a href="#cb66-2304" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-2305"><a href="#cb66-2305" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb66-2306"><a href="#cb66-2306" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2307"><a href="#cb66-2307" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb66-2308"><a href="#cb66-2308" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">6</span>,</span>
<span id="cb66-2309"><a href="#cb66-2309" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">TRUE</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2310"><a href="#cb66-2310" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2311"><a href="#cb66-2311" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.9</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2312"><a href="#cb66-2312" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2313"><a href="#cb66-2313" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2314"><a href="#cb66-2314" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-2315"><a href="#cb66-2315" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2316"><a href="#cb66-2316" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2317"><a href="#cb66-2317" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-2318"><a href="#cb66-2318" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-2319"><a href="#cb66-2319" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2320"><a href="#cb66-2320" aria-hidden="true" tabindex="-1"></a>t_b2_a</span>
<span id="cb66-2321"><a href="#cb66-2321" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2322"><a href="#cb66-2322" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2323"><a href="#cb66-2323" aria-hidden="true" tabindex="-1"></a>Plot table B2 - panel "b" (State Deputy - 2022)</span>
<span id="cb66-2324"><a href="#cb66-2324" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2327"><a href="#cb66-2327" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2328"><a href="#cb66-2328" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2329"><a href="#cb66-2329" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2330"><a href="#cb66-2330" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: plot-table-b2-b</span></span>
<span id="cb66-2331"><a href="#cb66-2331" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2332"><a href="#cb66-2332" aria-hidden="true" tabindex="-1"></a>v_year_election <span class="ot">=</span> <span class="dv">2022</span></span>
<span id="cb66-2333"><a href="#cb66-2333" aria-hidden="true" tabindex="-1"></a>min_week_revenue <span class="ot">&lt;-</span> <span class="st">'2022-08-21'</span></span>
<span id="cb66-2334"><a href="#cb66-2334" aria-hidden="true" tabindex="-1"></a>max_week_revenue <span class="ot">&lt;-</span> <span class="st">'2022-09-25'</span></span>
<span id="cb66-2335"><a href="#cb66-2335" aria-hidden="true" tabindex="-1"></a>t_b2_b <span class="ot">&lt;-</span> d_table_b2 <span class="sc">|&gt;</span></span>
<span id="cb66-2336"><a href="#cb66-2336" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year_election <span class="sc">==</span> v_year_election,</span>
<span id="cb66-2337"><a href="#cb66-2337" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&gt;=</span> min_week_revenue,</span>
<span id="cb66-2338"><a href="#cb66-2338" aria-hidden="true" tabindex="-1"></a>         week_revenue <span class="sc">&lt;=</span> max_week_revenue) <span class="sc">|&gt;</span></span>
<span id="cb66-2339"><a href="#cb66-2339" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tabulator</span>(</span>
<span id="cb66-2340"><a href="#cb66-2340" aria-hidden="true" tabindex="-1"></a>    <span class="at">rows =</span> <span class="fu">c</span>(<span class="st">"week_revenue"</span>, <span class="st">"race_color"</span>),</span>
<span id="cb66-2341"><a href="#cb66-2341" aria-hidden="true" tabindex="-1"></a>    <span class="at">columns =</span> <span class="fu">c</span>(<span class="st">"gender"</span>),</span>
<span id="cb66-2342"><a href="#cb66-2342" aria-hidden="true" tabindex="-1"></a>    <span class="st">`</span><span class="at">Revenue avg. (BRL)</span><span class="st">`</span> <span class="ot">=</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2343"><a href="#cb66-2343" aria-hidden="true" tabindex="-1"></a>      <span class="fu">as_chunk</span>(avg_public_revenue, <span class="at">formatter =</span> fmt_dbl)))</span>
<span id="cb66-2344"><a href="#cb66-2344" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2345"><a href="#cb66-2345" aria-hidden="true" tabindex="-1"></a>t_b2_b <span class="ot">&lt;-</span> <span class="fu">as_flextable</span>(t_b2_b) <span class="sc">|&gt;</span></span>
<span id="cb66-2346"><a href="#cb66-2346" aria-hidden="true" tabindex="-1"></a>  <span class="fu">labelizor</span>(</span>
<span id="cb66-2347"><a href="#cb66-2347" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>,</span>
<span id="cb66-2348"><a href="#cb66-2348" aria-hidden="true" tabindex="-1"></a>    <span class="at">labels =</span> <span class="fu">c</span>(</span>
<span id="cb66-2349"><a href="#cb66-2349" aria-hidden="true" tabindex="-1"></a>      <span class="st">"week_revenue"</span> <span class="ot">=</span> <span class="st">"Revenue registration week "</span>,</span>
<span id="cb66-2350"><a href="#cb66-2350" aria-hidden="true" tabindex="-1"></a>      <span class="st">"gender"</span> <span class="ot">=</span> <span class="st">"Gender"</span>,</span>
<span id="cb66-2351"><a href="#cb66-2351" aria-hidden="true" tabindex="-1"></a>      <span class="st">"race_color"</span> <span class="ot">=</span> <span class="st">"Race/color"</span>)) <span class="sc">|&gt;</span></span>
<span id="cb66-2352"><a href="#cb66-2352" aria-hidden="true" tabindex="-1"></a>  <span class="fu">add_header_row</span>(</span>
<span id="cb66-2353"><a href="#cb66-2353" aria-hidden="true" tabindex="-1"></a>    <span class="at">values =</span> <span class="fu">as_paragraph</span>(</span>
<span id="cb66-2354"><a href="#cb66-2354" aria-hidden="true" tabindex="-1"></a>      <span class="fu">fmt_signif_after_zeros</span>(v_year_election, <span class="at">digits =</span> <span class="dv">0</span>)),</span>
<span id="cb66-2355"><a href="#cb66-2355" aria-hidden="true" tabindex="-1"></a>    <span class="at">colwidths =</span> <span class="dv">6</span>,</span>
<span id="cb66-2356"><a href="#cb66-2356" aria-hidden="true" tabindex="-1"></a>    <span class="at">top =</span> <span class="cn">TRUE</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2357"><a href="#cb66-2357" aria-hidden="true" tabindex="-1"></a>  <span class="fu">align</span>(<span class="at">align =</span> <span class="st">"center"</span>, <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2358"><a href="#cb66-2358" aria-hidden="true" tabindex="-1"></a>  <span class="fu">width</span>(<span class="at">width =</span> <span class="fl">0.9</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2359"><a href="#cb66-2359" aria-hidden="true" tabindex="-1"></a>  <span class="fu">set_table_properties</span>(<span class="at">layout =</span> <span class="st">"fixed"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2360"><a href="#cb66-2360" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2361"><a href="#cb66-2361" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties1,</span>
<span id="cb66-2362"><a href="#cb66-2362" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"all"</span>) <span class="sc">|&gt;</span></span>
<span id="cb66-2363"><a href="#cb66-2363" aria-hidden="true" tabindex="-1"></a>  flextable<span class="sc">::</span><span class="fu">style</span>(</span>
<span id="cb66-2364"><a href="#cb66-2364" aria-hidden="true" tabindex="-1"></a>    <span class="at">pr_t =</span> properties2,</span>
<span id="cb66-2365"><a href="#cb66-2365" aria-hidden="true" tabindex="-1"></a>    <span class="at">part =</span> <span class="st">"header"</span>)</span>
<span id="cb66-2366"><a href="#cb66-2366" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2367"><a href="#cb66-2367" aria-hidden="true" tabindex="-1"></a>t_b2_b</span>
<span id="cb66-2368"><a href="#cb66-2368" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2369"><a href="#cb66-2369" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2370"><a href="#cb66-2370" aria-hidden="true" tabindex="-1"></a>Save table B-2</span>
<span id="cb66-2371"><a href="#cb66-2371" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2374"><a href="#cb66-2374" aria-hidden="true" tabindex="-1"></a><span class="in">```{r}</span></span>
<span id="cb66-2375"><a href="#cb66-2375" aria-hidden="true" tabindex="-1"></a><span class="co">#| warning: false</span></span>
<span id="cb66-2376"><a href="#cb66-2376" aria-hidden="true" tabindex="-1"></a><span class="co">#| message: false</span></span>
<span id="cb66-2377"><a href="#cb66-2377" aria-hidden="true" tabindex="-1"></a><span class="co">#| label: save-table-b-2</span></span>
<span id="cb66-2378"><a href="#cb66-2378" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2379"><a href="#cb66-2379" aria-hidden="true" tabindex="-1"></a>path <span class="ot">=</span> <span class="st">'..//Tabelas/Paper_Table_B-2_R.docx'</span></span>
<span id="cb66-2380"><a href="#cb66-2380" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2381"><a href="#cb66-2381" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">read_docx</span>()</span>
<span id="cb66-2382"><a href="#cb66-2382" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_b2_a)</span>
<span id="cb66-2383"><a href="#cb66-2383" aria-hidden="true" tabindex="-1"></a>doc <span class="ot">&lt;-</span> <span class="fu">body_add_flextable</span>(doc, <span class="at">value =</span> t_b2_b)</span>
<span id="cb66-2384"><a href="#cb66-2384" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(doc, <span class="at">target =</span> path)</span>
<span id="cb66-2385"><a href="#cb66-2385" aria-hidden="true" tabindex="-1"></a><span class="in">```</span></span>
<span id="cb66-2386"><a href="#cb66-2386" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb66-2387"><a href="#cb66-2387" aria-hidden="true" tabindex="-1"></a><span class="fu">### </span></span>
</code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div></div></div></div></div>
</div> <!-- /content -->



</body></html>